powershell 的字体名称

Cus*_*usp 5 powershell fonts truetype

我正在尝试编写一个 Poweshell 脚本来安装给定目录中的所有字体(格式为.ttf和)。.otf但是我想忽略已经安装的字体。为此,我需要获取字体的名称(而不是文件名)。

我怎样才能做到这一点?

Mic*_*lli 4

根据@LotPings 的评论进行编辑

您可以使用 .NET 来实现这一点。在以下示例中,您将浏览给定路径中的文件列表,然后使用 PrivateFontCollection 类来检索字体名称。

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
}
Run Code Online (Sandbox Code Playgroud)