-$null = foreach($font in Get-ChildItem -Recurse -Include *.ttf, *.otf) {
- [Session]::AddFontResource($font.FullName)
+$regFontPath = "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
+$fontRegistryPath = "HKCU:$regFontPath"
+$fontFiles = Get-ChildItem -Recurse -Include *.ttf, *.otf
+$null = foreach($font in $fontFiles) {
+ # See https://github.com/PPOSHGROUP/PPoShTools/blob/master/PPoShTools/Public/FileSystem/Add-Font.ps1#L80
+ Add-Type -AssemblyName System.Drawing
+ $objFontCollection = New-Object System.Drawing.Text.PrivateFontCollection
+ $objFontCollection.AddFontFile($font.FullName)
+ $FontName = $objFontCollection.Families.Name
+
+ $regTest = Get-ItemProperty -Path $fontRegistryPath -Name "*$FontName*" -ErrorAction SilentlyContinue
+ if (-not ($regTest)) {
+ New-ItemProperty -Name $FontName -Path $fontRegistryPath -PropertyType string -Value $font.FullName
+ Write-Output "Registering font {$($font.Name)} in registry with name {$FontName}"
+ }