Skip to content

Instantly share code, notes, and snippets.

@eamonburns
Last active June 2, 2025 17:25
Show Gist options
  • Select an option

  • Save eamonburns/fce3e0bd8cea53e47ff52e94e7022cc0 to your computer and use it in GitHub Desktop.

Select an option

Save eamonburns/fce3e0bd8cea53e47ff52e94e7022cc0 to your computer and use it in GitHub Desktop.
A simple PowerShell script to install all fonts of a certain type in a folder. Adapted from this Stack Overflow question: https://stackoverflow.com/questions/77829662/a-powershell-script-to-install-fonts-on-windows-11
param (
# Folder to search recursively for fonts to install
[string]$Folder = "$Env:USERPROFILE\Fonts\Ensure Installed",
# Array of glob patterns to match
[string[]]$Types = ("*.fon", "*.otf", "*.ttc", "*.ttf")
)
# Go through all folders in source and list all files
if (Test-Path -Path $Folder -Type Container) {
$fontList = Get-ChildItem `
-Path $Folder `
-Include $Types `
-Recurse
}
# Check if there are fonts
if ($fontList) {
foreach ($font in $fontList) {
Write-Host "Installing font - $($font.BaseName) ($($font.Extension.SubString(1)))"
try {
Copy-Item `
-Path $font `
-Destination "C:\Windows\Fonts" `
-ErrorAction Stop
} catch {
# Handle the PermissionDenied exception
switch ($_.CategoryInfo.Category) {
PermissionDenied {
Write-Host "You don't have the necessary permissions"
exit 1
}
default { throw }
}
}
try {
# Register font for all users
New-ItemProperty `
-Name $font.BaseName `
-Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" `
-PropertyType string `
-Value $font.Name `
-ErrorAction Stop
} catch {
# Handle the ResourceExists exception
switch ($_.CategoryInfo.Category) {
ResourceExists { Write-Host "The font has already been installed" }
default { throw }
}
}
}
} else {
Write-Host "There were no fonts to install in $Folder"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment