Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name of font by powershell

Tags:

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?

like image 535
Cusp Avatar asked May 21 '17 06:05

Cusp


1 Answers

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
}
like image 150
Micky Balladelli Avatar answered Sep 24 '22 11:09

Micky Balladelli