I'm trying to write a Poweshell script that installs all fonts (in formats .ttf
and .otf
) from a given directory. However I want to ignore fonts that are already installed. For that purpose I need to get the names (not the filenames) of the fonts.
How can I do that?
EDITED from comments from @LotPings
You can use .NET for that. In the following example you go through the list of files in a given path, then use the class PrivateFontCollection to retrieve the font names.
Add-Type -AssemblyName System.Drawing
$path = "<path to the fonts>\*.ttf"
$ttfFiles = Get-ChildItem $path
$fontCollection = new-object System.Drawing.Text.PrivateFontCollection
$ttfFiles | ForEach-Object {
$fontCollection.AddFontFile($_.fullname)
$fontCollection.Families[-1].Name
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With