Fonts Installation


I got a question. I wanted to install some fonts via Powershell. But I want to check first, if the font is already existing.

Maybe my workaround is not the odd way and also it doesn’t work while the if clause “array is not equal to the file in directory”.

Maybe someone can help me. Thanks a lot.

Kind regards Sam

#Dim Font Network Location (Source)
$NetPath = "\\srv01\Fonts\"

#Dim Font Temporay Location (Temp Source)
$TempPath= "C:\Temp\Fonts\"

#Dim Font Local Location (Local Source)
$FontPath = "C:\Windows\Fonts\"

#Dim Parameters
$Font = 0x14
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace($Font)

#Create Directory for Temporay Location
New-Item $TempPath -Type Directory -Force

#Copy Fonts from Network Location to Temporary Location
Copy-Item "$NetPath*" $TempPath

#Dim Temporary Fonts Directory
$TempDir = Dir $TempPath

ForEach($File in $TempDir)
$Array = @($File.Name)

#Dim Local Fonts Directory
$FontDir = Dir $FontPath

ForEach($FileDir in $FontDir)
ForEach($FileArr in $Array)
If ((Test-Path $File.Name) -ne $FileArr)

First, please highlight the code above and click the PRE, this will format the code for the forum. This code definitely looks like a converted VBScript with DIM declarations and WSHShell. I’d highly suggest searching for “Powershell Install Fonts”, there will be many examples of doing this in Powershell. To answer you question, you should be using comparison operators -contains or -in:

PS C:\Users\rasim> 'red','white','blue' -contains 'blue'

PS C:\Users\rasim> 'red','white','blue' -contains 'orange'

PS C:\Users\rasim> 'blue' -in 'red','white','blue'

PS C:\Users\rasim> 'orange' -in 'red','white','blue'

Hi Rob,

is there a tutorial how to set these code tags? I was trying to while writing my last post, but don’t know how to use them correctly. Thanks for your answer. No it wasn’t a vbscript but since i am more experienced in vba or vb it was just my way of comment the code. Are there any powershell guidelines how to comment recommended? Thanks, I will try the contains operator and give response if it worked.

Found the code tag explaining gif.