Install fonts via Intune
I needed to find a way to install some specific fonts to laptops using Microsoft Intune. A bit of googeling took me to: https://www.credera.com/blog/technology-solutions/windows-10-mobile-device-management-intune-part-3/ which I adapted for my needs.
1. Set up a storage blob or bucket with your cloud provider of choice
In this example I’m using an Azure storage blob which I’ll assume will be the most common method for Intune users.
2. Create a new InstallFonts.ps1 file and paste the contents below
$Fonts = @("font1.otf","font2.otf","font3.otf","font4.otf","font5.otf","font6.otf","font7.otf")
$RegFile = "InstallFonts.reg"
$FontURL = "https://yourstorageblob.blob.core.windows.net/yourfolder"
$LocalFontDir = "C:\Windows\Fonts"
function Import-Reg($path)
{
# This is necessary because some versions of reg.exe return their
# success messages on the error stream! :(
$cmd = [String]::Concat('reg import "', $path, '" 2>&1');
$output = & cmd.exe /c $cmd
$output = [String]::Concat(($output | % { $_.ToString() })).Trim();
if ($output -ilike "*success*")
{
echo $output;
}
else
{
throw $output;
}
}
foreach ($font in $Fonts){
$LocalFontFile = $LocalFontDir + "\" + $font
if (Test-Path $LocalFontFile) {
Write-Output "Already have $($font)"
}
else {
$FontUri = $FontURL + "/" + $font
Invoke-WebRequest -Uri $FontUri -OutFile "$LocalFontFile"
}
}
$RegUri = $FontURL + "/" + $RegFile
$OutputFile = "C:\" + $RegFile
Invoke-WebRequest -Uri $RegUri -OutFile $OutputFile
#reg import $OutputFile
Import-Reg $OutputFile
Registry error workaround from: https://github.com/chocolatey/choco/issues/249
3. Create a new Install Fonts script in Intune / Device Configuration / Scripts
Add the installfonts.ps file and assign it to a test group
4. Be sure you have the fonts installed on your system and extract their registry key entries
- Press CMD + R
- type regedit and hit enter
- click yes on the admin prompt
- Navigate to [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts] and export the whole folder
- Name the file InstallFonts.reg
- Edit the file and remove all but your custom fonts
- Your file should look something like this
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"Awesome Font 1 (TrueType)"="font1.otf"
"Awesome Font 2 (TrueType)"="font2.otf"
"Awesome Font 3 (TrueType)"="font3.otf"
"Awesome Font 4 (TrueType)"="font4.otf"
"Awesome Font 5 (TrueType)"="font5.otf"
"Awesome Font 6 (TrueType)"="font6.otf"
"Awesome Font 7 (TrueType)"="font7.otf"
You might have files ending in .ttf which is fine - just ensure the file names match those in the installfonts.ps file and you upload the matching files in the next step.
5. Upload everything
Upload your font files and the registry file to your storage blob.
6. Test everything
Ensure everything is working by adding your test users / machines to your test group or by running the PS script manually via ISE on a test machine.
7. Deploy
Assign to your production group(s)