1 min read

Let Powershell Install Fonts on Windows 11

Let Powershell Install Fonts on Windows 11

Installing 500 fonts in different directories is quite a job without automation on Windows.

The challenge:
A folder with subfolders and fonts in each.
Screenshot-2022-04-17-172346

The solution:

# Install all fonts in all sub folders.

Write-Output "Install fonts"

foreach ($folder in Get-ChildItem)
{
    Set-Location ${folder}
    Write-Output "Install fonts"
    $fonts = (New-Object -ComObject Shell.Application).Namespace(0x14)
    foreach ($file in Get-ChildItem *.otf)
    {
        $fileName = $file.Name
        if (-not(Test-Path -Path "C:\Windows\fonts\$fileName" )) {
            Write-Output $fileName
            dir $file | %{ $fonts.CopyHere($_.fullname) }
        }
    }
    Copy-Item *.otf c:\windows\fonts\
    Set-Location ..
}

This script is meant to be used for a systemwide installation, so it is run best as an administrator.