-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathGet-Font.ps1
48 lines (43 loc) · 1.54 KB
/
Get-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
function Get-Font {
<#
.SYNOPSIS
Gets the fonts currently loaded on the system
.DESCRIPTION
Uses the type System.Windows.Media.Fonts static property SystemFontFamilies,
to retrieve all of the fonts loaded by the system. If the Fonts type is not found,
the PresentationCore assembly will be automatically loaded
.PARAMETER Font
A wildcard to search for font names
.EXAMPLE
# Get All Fonts
Get-Font
.EXAMPLE
# Get All Lucida Fonts
Get-Font *Lucida*
.NOTES
This function will return the fonts that were present at the launch of the Powershell session.
If fonts are either added or deleted this function will not detect them until you launch
a new Powershell session.
Slight code fix in Where-Object logic. Previously it would return zero results
#>
[CmdletBinding(ConfirmImpact = 'None')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '')]
param(
[string] $Font = ''
)
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
if (-not ('Windows.Media.Fonts' -as [Type])) {
$null = Add-Type -AssemblyName 'PresentationCore'
}
$null = Add-Type -AssemblyName System.Drawing
$FontList = (New-Object -TypeName System.Drawing.Text.InstalledFontCollection).Families.Name
$FontList = $FontList | Sort-Object | Select-Object -Unique
$FontList | Where-Object { $_ -like "*$Font*" }
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}