{"id":4113,"date":"2022-02-22T07:00:00","date_gmt":"2022-02-22T06:00:00","guid":{"rendered":"https:\/\/scloud.work\/schriftarten-mit-intune-installieren-2\/"},"modified":"2023-08-18T14:27:41","modified_gmt":"2023-08-18T12:27:41","slug":"install-fonts-with-intune","status":"publish","type":"post","link":"https:\/\/scloud.work\/install-fonts-with-intune\/","title":{"rendered":"Install Fonts with Intune"},"content":{"rendered":"\n
Many fonts are already present in Windows 10 and 11. However, a company often has its own font, which is required for compliance with CI\/CD on all devices. This can be, for example, \"Open Sans\", the \"German-Swiss basic font\" or another font. In such cases I use a PowerShell script within a Win32 package to install \/ distribute the fonts via Intune. <\/p>\n\n\n\n
<\/p>\n\n\n
Like most of my packages, I build the Win32 package according to the same logic. I mentioned this earlier in the post \"my take on win32 apps - Intune<\/a>\" described. To install the font on a device, we have to copy it to the \"C:\\Windows\\Fonts\" directory and also register it in the Windows Registry under \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\".<\/p>\n\n\n\n Since most fonts consist of several TTF or OTF files, I have structured the package so that you can store them in the Fonts subdirectory. The copying process, including the creation of a registry key, is then carried out automatically for each TTF and\/or OTF file within this folder.<\/p>\n\n\n\n Incidentally, in order to be able to reinstall the same package with an extended font if necessary, I store a version in the validation file. <\/p>\n\n\n When uninstalling, I basically use the same logic as installing, simply that here a delete process is performed as opposed to a copy process and registry creation. I also delete the validation file.<\/p>\n\n\n The recognition rule is very simple and checks whether the validation file is available with the corresponding target version as content. If so, \"Found it!\" output and the Endpoint Manager or Intune knows that the package is available on the end device. <\/p>\n\n\n
In this example I am installing the font OpenSans by Google<\/a>, which is used in many websites. Incidentally, to install additional fonts via Intune, you only have to place them in the \"Fonts\" folder in the package and regenerate the intunewin.<\/p>\n\n\nInstalling fonts<\/h3>\n\n\n
$PackageName<\/span> = \"Company-Fonts\"<\/span>\n$Version<\/span> = \"1\"<\/span>\n\n$Path_local<\/span> = \"$Env:Programfiles<\/span>\\_MEM\"<\/span>\nStart-Transcript<\/span> -Path<\/span> \"$env:ProgramData<\/span>\\Microsoft\\IntuneManagementExtension\\Logs\\$PackageName<\/span>-install.log\"<\/span> -Force<\/span>\n\ntry<\/span>{\n\n $WorkingPath<\/span> = \"$Path_local<\/span>\\Data\\Fonts\"<\/span>\n New-Item<\/span> -ItemType<\/span> \"directory\"<\/span> -Path<\/span> $WorkingPath<\/span> -Force<\/span>\n Copy-Item<\/span> -Path<\/span> \".\\Fonts\\*\"<\/span> -Destination<\/span> $WorkingPath<\/span> -Recurse<\/span>\n\n $AllFonts<\/span> = @<\/span>()\n $AllFonts<\/span> += Get-ChildItem<\/span> -Path<\/span> \"$WorkingPath<\/span>\\*.ttf\"<\/span>\n $AllFonts<\/span> += Get-ChildItem<\/span> -Path<\/span> \"$WorkingPath<\/span>\\*.otf\"<\/span>\n\n foreach<\/span>($FontFile<\/span> in<\/span> $AllFonts<\/span>){\n try<\/span>{\n Copy-Item<\/span> -Path<\/span> \"$WorkingPath<\/span>\\$<\/span>($FontFile<\/span>.Name)\"<\/span> -Destination<\/span> \"$env:windir<\/span>\\Fonts\"<\/span> -Force<\/span> -PassThru<\/span> -ErrorAction<\/span> Stop\n New-ItemProperty<\/span> -Path<\/span> \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"<\/span> -Name<\/span> $FontFile<\/span>.Name -PropertyType<\/span> String -Value<\/span> $FontFile<\/span>.Name -Force<\/span>\n }catch<\/span>{\n Write-Error<\/span> $_<\/span>\n }\n }\n\n Remove-Item<\/span> $WorkingPath<\/span> -Force<\/span> -Recurse<\/span>\n\n New-Item<\/span> -Path<\/span> \"$Path_local<\/span>\\Validation\\$PackageName<\/span>\"<\/span> -ItemType<\/span> \"file\"<\/span> -Force<\/span> -Value<\/span> $Version<\/span>\n}catch<\/span>{\n Write-Host<\/span> \"_____________________________________________________________________\"<\/span>\n Write-Host<\/span> \"ERROR\"<\/span>\n Write-Host<\/span> \"$_<\/span>\"<\/span>\n Write-Host<\/span> \"_____________________________________________________________________\"<\/span>\n exit<\/span> 1618<\/span>\n}\nStop-Transcript<\/span>\n<\/code><\/span>Code language:<\/span> PowerShell<\/span> (<\/span>powershell<\/span>)<\/span><\/small><\/pre>\n\n
Uninstalling Fonts<\/h3>\n\n\n
$PackageName<\/span> = \"Company-Fonts\"<\/span>\n\n$Path_local<\/span> = \"$Env:Programfiles<\/span>\\_MEM\"<\/span>\nStart-Transcript<\/span> -Path<\/span> \"$env:ProgramData<\/span>\\Microsoft\\IntuneManagementExtension\\Logs\\$PackageName<\/span>-uninstall.log\"<\/span> -Force<\/span>\n\n$WorkingPath<\/span> = \"$Path_local<\/span>\\Data\\Fonts\"<\/span>\nNew-Item<\/span> -ItemType<\/span> \"directory\"<\/span> -Path<\/span> $WorkingPath<\/span> -Force<\/span>\nCopy-Item<\/span> -Path<\/span> \".\\Fonts\\*\"<\/span> -Destination<\/span> $WorkingPath<\/span> -Recurse<\/span>\n\n$AllFonts<\/span> = Get-ChildItem<\/span> -Path<\/span> \"$WorkingPath<\/span>\\*.ttf\"<\/span>\n$AllFonts<\/span> += Get-ChildItem<\/span> -Path<\/span> \"$WorkingPath<\/span>\\*.otf\"<\/span>\n\nforeach<\/span>($FontFile<\/span> in<\/span> $AllFonts<\/span>){\n try<\/span>{\n Remove-Item<\/span> -Path<\/span> \"$WorkingPath<\/span>\\$<\/span>($FontFile<\/span>.Name)\"<\/span> -Force<\/span>\n Remove-ItemProperty<\/span> -Path<\/span> \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"<\/span> -Name<\/span> $FontFile<\/span>.Name -Force<\/span>\n }catch<\/span>{\n Write-Host<\/span> $_<\/span>\n }\n}\n\nRemove-Item<\/span> $WorkingPath<\/span> -Force<\/span> -Recurse<\/span>\n\nRemove-Item<\/span> -Path<\/span> \"$Path_local<\/span>\\Validation\\$PackageName<\/span>\"<\/span> -ItemType<\/span> \"file\"<\/span> -Force<\/span> -Value<\/span> $Version<\/span>\n\nStop-Transcript<\/span><\/code><\/span>Code language:<\/span> PowerShell<\/span> (<\/span>powershell<\/span>)<\/span><\/small><\/pre>\n\n
Detection rule<\/h3>\n\n\n
$PackageName<\/span> = \"Company-Fonts\"<\/span>\n$Version<\/span> = \"1\"<\/span>\n$Path_local<\/span> = \"$Env:Programfiles<\/span>\\_MEM\"<\/span>\n$ProgramVersion_current<\/span> = Get-Content<\/span> -Path<\/span> \"$Path_local<\/span>\\Validation\\$PackageName<\/span>\"<\/span>\n\nif<\/span>($ProgramVersion_current<\/span> -eq<\/span> $Version<\/span>){\n Write-Host<\/span> \"Found it!\"<\/span>\n}<\/code><\/span>Code language:<\/span> PowerShell<\/span> (<\/span>powershell<\/span>)<\/span><\/small><\/pre>\n\n
Create and distribute Win32 package<\/h3>\n\n\n