forked from tonypags/PsWinAdmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-TrueTypeFont.ps1
More file actions
106 lines (67 loc) · 2.67 KB
/
Copy pathAdd-TrueTypeFont.ps1
File metadata and controls
106 lines (67 loc) · 2.67 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# issue discovered here:
# https://eddiejackson.net/wp/?p=16137
function Add-TrueTypeFont {
<#
.SYNOPSIS
Adds TTF files to Windows.
.DESCRIPTION
Adds TTF files to Windows Control Panel on the local computer only. Must run as admin.
.EXAMPLE
dir \\server\share\fonts\*.ttf | Add-TrueTypeFont
#>
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName=$true,
Position=0)]
[ValidatePattern('.+\.ttf$')]
[Alias('FilePath','FullName')]
[string[]]
$Path
)
begin {
# Namespace ID
$FONTS = 0x14
Set-Variable -Name ErrorActionPreference -Scope Script -Value 'Stop'
Try {
$objShell = New-Object -ComObject Shell.Application
} Catch {
throw "Missing COMObject: Shell.Application"
}
Try {
$objFolder = $objShell.Namespace($FONTS)
} Catch {
throw "Unable to load Font Namespace:`n$($_.Exception.Message)"
}
Set-Variable -Name ErrorActionPreference -Scope Script -Value 'SilentlyContinue'
}
process {
Foreach ($p in $Path) {
$objFile = Get-Item $p
$FontName = $objFile.name
if (Test-Path "c:\windows\fonts\$FontName") {
Write-Verbose "Font already installed: $($FontName)"
} else {
if (Test-Path $objFile.FullName) {
$CopyOptions = 4 + 16; # from https://www.reddit.com/r/sysadmin/comments/a64lax/windows_1809_breaks_powershell_script_to_install/ebs68wj?utm_source=share&utm_medium=web2x
[void]($ObjFolder.CopyHere($objFile.fullname, $CopyOptions));
$regPath = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts"
New-ItemProperty -Name $objFile.fullname -Path $regPath -PropertyType string -Value ($objFile.fullname)
# Test each action
$Installed = Get-Font $FontName
if ($Installed) {
Write-Verbose "Font successfully installed: $($FontName)"
} else {
Write-Warning "Font not installed: $($FontName)!"
}
} else {
Write-Warning "Path not found: $($objFile.fullname)"
}
}
}
}
end {
if ($Error) {
$Error | ForEach-Object { Write-Verbose $_.Exception.Message }
}
}
}