-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-Font.ps1
62 lines (45 loc) · 2.33 KB
/
add-Font.ps1
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#Script to Install Fonts
#Check for font
#$fonts = (New-Object -ComObject Shell.Application).Namespace(0x14)
$DC = "ctsdc1"
$Path = Test-Path \\$DC\netlogon\font
if($Path -eq $true)
{
Write-EventLog -Source Application -LogName Application -EventId 301 -EntryType Information -Message "The Network Path is True"
$fontFolder = "\\$DC\NETLOGON\Font"
$fontItem = Get-Item -Path $fontFolder
$fontList = Get-ChildItem -Path "$fontItem\*" -Include ('*.fon','*.otf','*.ttc','*.ttf')
$RegPath =(Test-Path 'HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Fonts')
$objFont = New-Object System.Drawing.Text.PrivateFontCollection
}else{
Write-EventLog -Source Application -LogName Application -EventId 309 -EntryType Error -Message "Path not reachable"
}
foreach ($font in $fontList)
{
#Font Object Construction
$objFont.AddFontFile($font.FullName)
$objTitle = $objFont.Families[-1].Name
$fontName = $font.Name
$objExtension = switch ($font.Extension)
{
.TTF {"(TrueType)"}
.OTF {"(OpenType)"}
Default {
Write-EventLog -Source Application -LogName Application -EventId 305 -EntryType Information -Message "Font Extension not Found"
}
}
$FontTitle = $objTitle + " " + $objExtension
#Conditionals To determine necessary functions of installation.
if (-not(Test-Path -Path "C:\Windows\fonts\$fontName" ))
{
Write-EventLog -Source Application -LogName Application -EventId 302 -EntryType Information -Message "Font not Found, Installing font."
echo $fontName
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v $FontTitle /t REG_SZ /d DWBAR39.TTF /f
cp $font C:\Windows\Fonts
}if(Test-Path -Path "C:\Windows\fonts\$fontName")
{
Write-EventLog -Source Application -LogName Application -EventId 303 -EntryType Information -Message "Font successfully Installed in C:\windows\fonts"
}else{
Write-EventLog -Source Application -LogName Application -EventID 310 -EntryType Information -Message "Font failed to install in C:\windows\fonts"
}
}