I have a collection of OpenType font files which are all different styles of the same family:
In order to install these fonts via PowerShell and properly add them to the registry, I need to know their friendly style name.
When I install "FreigSanLFProBol.otf" via Windows Explorer, the registry key contains this data:
{
name: "FreightSansLFPro Bold (TrueType)",
type: REG_SZ,
data: "FreigSanLFProBol.otf"
}
The problem is I have no idea how to programmatically identify the value in the "name" key from the font file itself.
Using the information available in Name of font by powershell, I was able to get most of the way there:
$path = "C:\Windows\Fonts\FreigSanLFProBol.otf"
Add-Type -AssemblyName System.Drawing
$fontCollection = New-Object System.Drawing.Text.PrivateFontCollection
$fontCollection.AddFontFile($(Get-Item $path).fullname)
$fontCollection.Families[-1].Name
That gives me the result of "FreightSansLFPro" - which is different than the reg key value which gives it as "FreightSansLFPro Bold". (Never mind the fact that the reg key still lists the type as "TrueType Font" even though it's an OpenType Font).
Where does it get "Bold" from, and how do I get that specific value/name from the font file programmatically?
$folder = "C:\Windows\fonts\"
$objShell = New-Object -ComObject Shell.Application
$fileList = @()
$attrList = @{}
$details = ( "Title",
"Font style",
"Show/hide",
"Designed for",
"Category",
"Designer/foundry" ,
"Font Embeddability",
"Font type",
"Family",
"Date created",
"Date modified",
"Collection",
"Font file names",
"Font version"
)
#figure out what the possible metadata is
$objFolder = $objShell.namespace($folder)
for ($attr = 0 ; $attr -le 500; $attr++)
{
$attrName = $objFolder.getDetailsOf($objFolder.items, $attr)
if ( $attrName -and ( -not $attrList.Contains($attrName) ))
{
$attrList.add( $attrName, $attr )
}
}
#$attrList
#loop through all the fonts, and process
$objFolder = $objShell.namespace($folder)
foreach($file in $objFolder.items())
{
foreach( $attr in $details)
{
$attrValue = $objFolder.getDetailsOf($file, $attrList[$attr])
if ( $attrValue )
{
Add-Member -InputObject $file -MemberType NoteProperty -Name $attr -value $attrValue
}
}
$fileList += $file
write-verbose "Prcessing file number $($fileList.Count)"
}
$fileList | select $details | out-gridview
Source: https://forums.powershell.org/t/listing-font-details/9230