Question:
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?
Answer:
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.
1 2 3 4 5 6 7 8 9 10 11 12 |
Add-Type -AssemblyName System.Drawing $path = " $ttfFiles = Get-ChildItem $path $fontCollection = new-object System.Drawing.Text.PrivateFontCollection $ttfFiles | ForEach-Object { $fontCollection.AddFontFile($_.fullname) $fontCollection.Families[-1].Name } |