forked from MicksITBlogs/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallFonts.ps1
More file actions
97 lines (85 loc) · 2.98 KB
/
InstallFonts.ps1
File metadata and controls
97 lines (85 loc) · 2.98 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
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.93
Created on: 9/18/2015 9:44 AM
Created by: Mick Pletcher
Filename: install.ps1
===========================================================================
.DESCRIPTION
This script will install all fonts of the specified font type from
the specified directory location. All of the fonts you want installed
are to be placed in the specified directory location. The script will
then read all files in that location and filter out for the specified
font type. It will then install each font individually and output
the status on whether it installed or not.
#>
function Get-RelativePath {
<#
.SYNOPSIS
Get-RelativePath
.DESCRIPTION
Defines the path which this script is being executed from
.EXAMPLE
$RelativePath = Get-RelativePath
#>
#Declare Local Variables
Set-Variable -Name RelativePath -Scope Local -Force
$RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent) + "\"
Return $RelativePath
#Cleanup Local Variables
Remove-Variable -Name RelativePath -Scope Local -Force
}
Function Install-Fonts {
<#
.SYNOPSIS
Install-Fonts
.DESCRIPTION
Installs all fonts in the designated source directory.
.EXAMPLE
Install-Fonts -SourceDirectory "c:\Fonts" -FontType "ttf"
#>
Param ([String]
$SourceDirectory,
[String]
$FontType)
#Define Local Variables
Set-Variable -Name File -Scope Local -Force
Set-Variable -Name Files -Scope Local -Force
Set-Variable -Name Fonts -Scope Local -Force
Set-Variable -Name i -Scope Local -Force
Set-Variable -Name sa -Scope Local -Force
$FontType = "*." + $FontType
$sa = new-object -comobject shell.application
$Fonts = $sa.NameSpace(0x14)
$Files = Get-ChildItem $SourceDirectory -Filter $FontType
For ($i = 0; $i -lt $Files.Count; $i++) {
$Output = $Files[$i].Name + "....."
Write-Host $Files[$i].Name"....." -NoNewline
$File = $Env:windir + "\Fonts\" + $Files[$i].Name
If ((Test-Path $File) -eq $false) {
$Fonts.CopyHere($Files[$i].FullName)
If ((Test-Path $File) -eq $true) {
Write-Host "Installed" -ForegroundColor Yellow
} else {
Write-Host "Failed" -ForegroundColor Red
}
} else {
Write-Host "Installed" -ForegroundColor Yellow
}
}
#Cleanup Local Variables
Remove-Variable -Name File -Scope Local -Force
Remove-Variable -Name Files -Scope Local -Force
Remove-Variable -Name Fonts -Scope Local -Force
Remove-Variable -Name i -Scope Local -Force
Remove-Variable -Name sa -Scope Local -Force
}
#Declare Local Variables
Set-Variable -Name RelativePath -Scope Local -Force
cls
$RelativePath = Get-RelativePath
Install-Fonts -SourceDirectory $RelativePath -FontType "ttf"
Install-Fonts -SourceDirectory $RelativePath -FontType "otf"
#Cleanup Local Variables
Remove-Variable -Name RelativePath -Scope Local -Force