-
Notifications
You must be signed in to change notification settings - Fork 0
/
FontInstall
41 lines (32 loc) · 1.66 KB
/
FontInstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$StorageAccountContext = New-AzStorageContext -StorageAccountName "ENTER YOUR STORAGE ACCOUNT NAME" -SasToken "ENTER YOUR SAS TOKEN" -ErrorAction Stop
$blobContents = Get-AzStorageBlob -Container "fonts" -Context $StorageAccountContext -ErrorAction Stop
$logfile = "C:/ProgramData/Microsoft/IntuneApps/FontInstall.log"
foreach ($blobContent in $blobContents)
{
#Download the blobs
$localPath = "C:\Windows\Fonts\" + $blobContent.Name
# Check if the file already exists locally
if (!(Test-Path $localPath)){
Get-AzStorageBlobContent -Container "fonts" -Blob $blobContent.Name -Context $StorageAccountContext -Destination $localPath -Force -ErrorAction Stop
# Get the font name
$fontFile = "C:\Windows\Fonts\$($blobContent.Name)"
$fontCollection = New-Object System.Drawing.Text.PrivateFontCollection
$fontCollection.AddFontFile($fontFile)
$fontFamily = $fontCollection.Families[0]
$fontName = $fontFamily.Name
# Add font type depending on file extension
if ($blobContent.Name.EndsWith(".ttf")) {
$fontName += " (TrueType)"
} elseif ($blobContent.Name.EndsWith(".otf")) {
$fontName += " (OpenType)"
}
# Add the font to the registry
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" -Name "$fontName" -Value $blobContent.Name -Force
$message = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): Installed $($blobContent.Name) is $($fontName)"
Write-Output $message | Out-File $logfile -Append
} else {
# File already exists locally, skip downloading
$message = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): File $($blobContent.Name) already exists, skipping."
Write-Output $message | Out-File $logfile -Append
}
}