Skip to content

Instantly share code, notes, and snippets.

@ddieppa
Last active August 5, 2019 11:37
Show Gist options
  • Save ddieppa/c2bea8dccf6c4ce6cd9e33dac021efb3 to your computer and use it in GitHub Desktop.
Save ddieppa/c2bea8dccf6c4ce6cd9e33dac021efb3 to your computer and use it in GitHub Desktop.
# Source for this script: https://www.mondaiji.com/blog/other/it/10247-windows-install-fonts-via-command-line
# create temp directory
$tempPath = "C:\InstallFont"
# Obtain system font folder for extraction
$fonts = 0x14
$shell = New-Object -ComObject Shell.Application
$SystemFontsFolder = $shell.Namespace($fonts)
$FontFiles = Get-ChildItem -Path tempPath -Recurse -File -Include '*.ttf', '*.otf'
$SystemFontsPath = $SystemFontsFolder.Self.Path
foreach ($FontFile in $FontFiles) {
# $FontFile will be copied to this path:
$targetPath = Join-Path $SystemFontsPath $FontFile.Name
# So, see if target exists...
if (Test-Path $targetPath) {
# font file with the same name already there.
# delete and replace.
Remove-Item $targetPath -Force
Copy-Item $FontFile.FullName $targetPath -Force
}
else {
#install the font.
$SystemFontsFolder.CopyHere($FontFile.fullname)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment