trbdk3-Install-Fonts.ps1
<#PSScriptInfo .VERSION 1.0 .GUID 147321c3-d793-40d2-a381-320100ed81f6 .AUTHOR TimB .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Windows 10 1809 printer deployment script #> Param() Function Install-Font { <# .Synopsis Installs one or more fonts. .Parameter FontPath The path to the font to be installed or a directory containing fonts to install. .Parameter Recurse Searches for fonts to install recursively when a path to a directory is provided. .Notes This script is derived from another entry on the ps gallery - https://www.powershellgallery.com/packages/PSWinGlue/0.3.3/Content/Functions%5CInstall-Font.ps1 Due to bugs in the 1809 handling for the installation process this makes use of basic file copies and manually registering fonts under HKLM. See https://serverfault.com/questions/943895/powershell-font-deploys-for-1809 #> [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [String]$FontPath, [Switch]$Recurse ) $ErrorActionPreference = 'Stop' if (Test-Path -Path $FontPath) { $FontItem = Get-Item -Path $FontPath if ($FontItem -is [IO.DirectoryInfo]) { if ($Recurse) { $Fonts = Get-ChildItem -Path $FontItem -Include ('*.fon','*.otf','*.ttc','*.ttf') -Recurse } else { $Fonts = Get-ChildItem -Path "$FontItem\*" -Include ('*.fon','*.otf','*.ttc','*.ttf') } if (!$Fonts) { throw ('Unable to locate any fonts in provided directory: {0}' -f $FontItem.FullName) } } elseif ($FontItem -is [IO.FileInfo]) { if ($FontItem.Extension -notin ('.fon','.otf','.ttc','.ttf')) { throw ('Provided file does not appear to be a valid font: {0}' -f $FontItem.FullName) } $Fonts = $FontItem } else { throw ('Expected directory or file but received: {0}' -f $FontItem.GetType().Name) } } else { throw ('Provided font path does not appear to be valid: {0}' -f $FontPath) } foreach ($Font in $Fonts) { Write-Host ('Installing font: {0}' -f $Font.BaseName) #$Font Copy $Font "C:\Windows\Fonts" New-ItemProperty -Name $Font.BaseName -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -PropertyType string -Value $Font.name } } # Install-Font . |