A while back the topic of scripting the installation and removal of fonts came up in an internal discussion. It reminded me that someone had once shared with me Visual Basic 6 utilities for doing just that. So I decided to see if I could transform these into working Windows PowerShell scripts in the same way that I had rewritten my utility to set the time zone. Like my time zone utility, these utilities used Windows APIs to install and remove fonts. Specifically they used AddFontResource and RemoveFontResource (plus PostMessage to notify running applications of the change).
Attached are the results of this effort. Add-Font.ps1 can be used to install a single font file or a folder of fonts. Remove-Font.ps1 can be used to uninstall a single font file installed in the \Windows\Fonts folder. These script are written for Windows PowerShell version 2. Run each script with the -help switch for usage details. They have only been tested on my computer so like anything else posted to this blog, please test them first and use at your own risk.
Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use.
This post was contributed by Michael Murgolo, a Senior Consultant with Microsoft Services - U.S. East Region.
Thanks for this script. Have you also a script or a extension for this script to install Type 1 Fonts?
Hi Michael,
Thanks for developing these. I am trying to run Add-Font.ps1 on Windows 2008 R2 using the folder parameter, but am coming across the following error.
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At \\lonvsp01\WisdomResources\PowershellScripts\Add-Font.ps1:549 char:19
+ if ((Test-Path <<<< $path -PathType Leaf) -eq $true)
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingVa
lidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl
lowed,Microsoft.PowerShell.Commands.TestPathCommand
I find this unusual as I am using -folder, and yet it seems to be stuck at the point of evaluating whether the parameter is a file or not.
I hope you can assist with this.
Geoff