AutomoxAutomox

Install a Font to the Windows Font Library

Tony-Automox
April 28, 2021 at 11:01 pm UTC

This worklet will add a TTF or OTF font to your Windows font library. Just upload the .ttf or .otf file to the worklet and set $font to the name of the uploaded font file in the evaluation and remediation.

Evaluation:

3 lines
$font = "NAME_OF_FONT.ttf"

If (Test-Path "c:\windows\fonts\$($font)") { Exit 0 } else { Exit 1 }

Remediation:

powershell21 lines
$font = "NAME_OF_FONT.ttf"

    try {
        If (!(Test-Path "c:\windows\fonts\$($font)")) {
            switch (($font -split "\.")[-1]) {
                "TTF" {
                    $fn = "$(($font -split "\.")[0]) (TrueType)"
                    break
                }
                "OTF" {
                    $fn = "$(($font -split "\.")[0]) (OpenType)"
                    break
                }
            }
            Copy-Item $font -Destination "C:\Windows\Fonts\$font" -Force
            New-ItemProperty -Name $fn -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -PropertyType string -Value $font
        }
    }
    catch {
        write-warning $_.exception.message
    }

This discussion is archived and closed to replies. Continue it in the Automox Community Slack.

Discuss on Slack

Replies (5)

LantzApril 29, 2021
#1

@Tony Thanks! This is awesome!

uapiladoJune 30, 2021
#2

Hi @Tony,

Thanks for this worklet. I wonder if you have for MacOS version for installing font.

cc: @automoxsupport

Best,
Ulyssis

mshethOctober 19, 2021
#3

Thank you,

Tony, I need one more help. I have 20 other fonts, how can I add this to worklet.

mshethOctober 28, 2021
#4

Hello,

I need your help with when trying this I am getting WARNING: Cannot bind argument to parameter ‘Name’ because it is null.

$font = “‘EncodeSans-Black.ttf’,‘EncodeSans-Bold.ttf’,‘EncodeSansCondensed-Black.ttf’,‘EncodeSansCondensed-Bold.ttf’,‘EncodeSansCondensed-ExtraBold.ttf’,‘EncodeSansCondensed-ExtraLight.ttf’,‘EncodeSansCondensed-Light.ttf’,‘EncodeSansCondensed-Medium.ttf’
,‘EncodeSansCondensed-Regular.ttf’,‘EncodeSansCondensed-SemiBold.ttf’,‘EncodeSans-ExtraBold.ttf’,‘EncodeSans-ExtraLight.ttf’,‘EncodeSans-Light.ttf’,‘EncodeSans-Medium.ttf’,‘EncodeSans-Regular.ttf’,‘EncodeSans-SemiBold.ttf’,‘EncodeSans-Thin.ttf’”

powershell19 lines
try {
    If (!(Test-Path "c:\windows\fonts\$($font)")) {
        switch (($font -split "\.")[-1]) {
            "TTF" {
                $fn = "$(($font -split "\.")[0]) (TrueType)"
                break
            }
            "OTF" {
                $fn = "$(($font -split "\.")[0]) (OpenType)"
                break
            }
        }
        Copy-Item $font -Destination "C:\Windows\Fonts\$font" -Force
        New-ItemProperty -name $fn -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -PropertyType string -Value $font
    }
}
catch {
    write-warning $_.exception.message
}

if you can help that would be great.

it_stuckMarch 31, 2023
#5

Holy thread resurrection!

Don’t suppose anyone knows how to install multiple fonts in once script?