Computer >> Computer tutorials >  >> System >> Windows Server

Installing Fonts in Windows Using GPO and PowerShell

In this article, we’ll show how to install additional fonts on computers in an Active Directory domain using Group Policy and PowerShell script. This guide was tested on current Windows 10 20H2 and Windows Server 2016/2019 builds.

Contents:

  • Deploying New Fonts via GPO
  • Install Windows Fonts Using PowerShell Logon Script

Deploying New Fonts via GPO

If you want to install one or two new fonts, you can do it using the Group Policy. To install a font, copy a *.ttf file to %WindowsDir%\Fonts\ on a client computer and add the new font information to the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts registry key.

  1. Copy the TTF font file to a shared network folder on your file server (if you have only some new fonts, you can store them in SYSVOL folder on your domain controller); Installing Fonts in Windows Using GPO and PowerShell
  2. Open the domain Group Policy Management console (gpmc.msc), create a new policy GPO_InstallFonts and link it to the OU with computers; Installing Fonts in Windows Using GPO and PowerShell
  3. Edit the policy;
  4. Create a new rule in Group Policy Preferences to copy a font file from the shared folder to %WindowsDir%\Fonts\ on your client devices. Earlier we showed how to copy a file to computers using GPO. Create a group policy following these instructions. Go to Computer Configuration -> Preferences -> Windows Settings -> Files. Create a policy entry with the parameters below:Source: \\woshub.com\SYSVOL\woshub.com\scripts\Fonts\Roboto-Black.ttf
    Destination:  %WindowsDir%\Fonts\Roboto-Black.ttf

    Installing Fonts in Windows Using GPO and PowerShell

  5. Now you need to add the information about your new font to the registry. To make changes to the registry using GPO you can also use GPP (Computer Configuration -> Preferences -> Windows Settings -> Registry);
  6. You can specify the font information in the registry manually. However, it is easier to install a font manually on a reference computer and export the font registry settings using a wizard (Computer Configuration -> Preferences -> Windows Settings -> Registry -> New -> Registry Wizard); Installing Fonts in Windows Using GPO and PowerShell
  7. Use the Registry Browser to go to HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts reg key on a remote computer. Find and select the registry item containing the name of the font you want to install; Installing Fonts in Windows Using GPO and PowerShell
  8. The registry parameter will appear in the GPO editor.

Installing Fonts in Windows Using GPO and PowerShell

Then update GPO settings on the client computer and make sure that the new font file has been installed. In Windows 10, you can view the list of installed fonts in the Settings -> Personalization -> Fonts.

Installing Fonts in Windows Using GPO and PowerShell

If the font file has not been installed, make sure that the policy is assigned to the computer using the gpresult tool. Then follow the usual way for troubleshooting issues with applying GPO settings to computers.

Install Windows Fonts Using PowerShell Logon Script

It is worth to use the font installation method using GPO described above if you want to install some fonts only. If you want to install a lot of new font files at once, it is better to use a PowerShell script, since it may be tiresome to create special policy options for each font.

The following PowerShell script will install all *.ttf and *.otf font files located in the specified shared folder. Also, the script writes all actions to the log file using the WriteLog function.

function WriteLog
{
Param ([string]$LogString)
$Stamp = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
$LogMessage = "$Stamp $LogString"
Add-content $LogFile -value $LogMessage
}
$Logfile = "C:\Windows\posh_font_install.log"
$SourceFolder = "\\woshub.com\SYSVOL\woshub.com\scripts\Fonts"
Add-Type -AssemblyName System.Drawing
$WindowsFonts = [System.Drawing.Text.PrivateFontCollection]::new()
Get-ChildItem -Path $SourceFolder -Include *.ttf, *.otf -Recurse -File |
Copy-Item -Destination "$env:SystemRoot\Fonts" -Force -Confirm:$false -PassThru |
ForEach-Object {
WriteLog "Installing font file $_.name"
$WindowsFonts.AddFontFile($_.fullname)
$RegistryValue = @{
Path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts'
Name = $WindowsFonts.Families[-1].Name
Value = $_.Fullname
}
$RemoveRegistry = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
Remove-ItemProperty -name $($WindowsFonts.Families[-1].Name) -path $RemoveRegistry
New-ItemProperty @RegistryValue
}

Installing Fonts in Windows Using GPO and PowerShell

Save the PowerShell script as a PS1 file and run it as a logon script using GPO.

Thus, all font files from the specified folder will be installed in Windows, and the installation date and time will be logged.

Installing Fonts in Windows Using GPO and PowerShell

If you need to remove all additional fonts in Windows and restore the default ones, follow this guide.