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
72 lines (62 loc) · 2.06 KB
/
InstallFonts.ps1
File metadata and controls
72 lines (62 loc) · 2.06 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
<#
.SYNOPSIS
Install Fonts
.DESCRIPTION
Install all designated fonts that reside in the same directory as this script. By designated, this means TTF, OTF, and such defined in the -FontType parameter for the InstallFonts function.
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.145
Created on: 2/14/2018 2:39 PM
Created by: Mick Pletcher
Filename: InstallFonts.ps1
===========================================================================
#>
[CmdletBinding()]
param ()
function Get-RelativePath {
<#
.SYNOPSIS
Get the relative path
.DESCRIPTION
Returns the location of the currently running PowerShell script
#>
[CmdletBinding()][OutputType([string])]
param ()
$Path = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent) + "\"
Return $Path
}
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)
$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++) {
$FontName = $Files[$i].Name.ToString().Trim()
Write-Host "Installing"$FontName"....." -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
Exit 1
}
} else {
Write-Host "Already Installed" -ForegroundColor Yellow
}
}
}
Clear-Host
$RelativePath = Get-RelativePath
$Success = Install-Fonts -SourceDirectory $RelativePath -FontType "ttf"