I needed a script for a customer of mine to search a share on the network and install fonts. I had already create a script with the support from the community. That worked but it kept trying to install Fonts that had already been installed. This caused problems as a box would popup asking do you want to override. With 1000+ Fonts it caused some issues.
The customer needed to have all fonts installed across all the computers as it needed to design the print on a couple of computer then print using others.
After searching the web and connecting scripts together I manage to get it working. So I thought I would share. If it helped me, it may help others.
I would never call myself a coder so others may find better ways of doing this. But with the script it will look at the location you select on $Path= and then check C:\Users$username\AppData\Local\Microsoft\Windows\Fonts for any that have already been installed. It will also only install files that are .fon .otf .ttc and .ttf. I needed this bit as users tend to also put some images in this location even when told not to.
$FONTS = 0x14
$Path="\\NAS LOCATION\Fonts"
$FontItem = Get-Item -Path $Path
$FontList = Get-ChildItem -Path "$FontItem\*" -Include ('*.fon','*.otf','*.ttc','*.ttf')
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace($FONTS)
$Fontdir = dir $Path
$username = $env:UserName
foreach($File in $FontList) {
if(!($file.name -match "pfb$"))
{
$try = $true
$installedFonts = @(Get-ChildItem C:\Users\$username\AppData\Local\Microsoft\Windows\Fonts | Where-Object {$_.PSIsContainer -eq $false} | Select-Object basename)
$name = $File.baseName
foreach($font in $installedFonts)
{
$font = $font -replace "_", ""
$name = $name -replace "_", ""
if ($font -match $name)
{
$try = $false
}
}
if ($try)
{
$objFolder.CopyHere($File.fullname)
}
}
}
Credits goes to the following people/Posts. Jordan Malcolm - https://jordanmalcolm.com/deploying-windows-10-fonts-at-scale/ CloudCompanyApps - https://cloudcompanyapps.com/2019/06/06/install-windows-fonts-with-powershell/