forked from proxb/PowerShell_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-Icon.ps1
188 lines (164 loc) · 8.1 KB
/
Get-Icon.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
Function Get-Icon {
<#
.SYNOPSIS
Gets the icon from a file
.DESCRIPTION
Gets the icon from a file and displays it in a variety formats.
.PARAMETER Path
The path to a file to get the icon
.PARAMETER ToBytes
Displays outputs as a byte array
.PARAMETER ToBitmap
Display the icon as a bitmap object
.PARAMETER ToBase64
Displays the icon in Base64 encoded format
.NOTES
Name: Get-Icon
Author: Boe Prox
Version History:
1.0 //Boe Prox - 11JAN2016
- Initial version
.OUTPUT
System.Drawing.Icon
System.Drawing.Bitmap
System.String
System.Byte[]
.EXAMPLE
Get-Icon -Path 'C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe'
FullName : C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe
Handle : 164169893
Height : 32
Size : {Width=32, Height=32}
Width : 32
Description
-----------
Returns the System.Drawing.Icon representation of the icon
.EXAMPLE
Get-Icon -Path 'C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe' -ToBitmap
Tag :
PhysicalDimension : {Width=32, Height=32}
Size : {Width=32, Height=32}
Width : 32
Height : 32
HorizontalResolution : 96
VerticalResolution : 96
Flags : 2
RawFormat : [ImageFormat: b96b3caa-0728-11d3-9d7b-0000f81ef32e]
PixelFormat : Format32bppArgb
Palette : System.Drawing.Imaging.ColorPalette
FrameDimensionsList : {7462dc86-6180-4c7e-8e3f-ee7333a7a483}
PropertyIdList : {}
PropertyItems : {}
Description
-----------
Returns the System.Drawing.Bitmap representation of the icon
.EXAMPLE
$FileName = 'C:\Temp\PowerShellIcon.png'
$Format = [System.Drawing.Imaging.ImageFormat]::Png
(Get-Icon -Path 'C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe' -ToBitmap).Save($FileName,$Format)
Description
-----------
Saves the icon as a file.
.EXAMPLE
Get-Icon -Path 'C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe' -ToBase64
AAABAAEAICAQHQAAAADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAgAIAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAgICAAMDAwAAAAP8AAP8AAAD//wD/AAAA/wD/AP
//AAD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABmZmZmZmZmZmZmZgAAAAAAaId3d3d3d4iIiIdgAA
AHdmhmZmZmZmZmZmZoZAAAB2ZnZmZmZmZmZmZmZ3YAAAdmZ3ZmiHZniIiHZmaGAAAHZmd2Zv/4eIiIi
GZmhgAAB2ZmdmZ4/4eIh3ZmZnYAAAd2ZnZmZo//h2ZmZmZ3YAAHZmaGZmZo//h2ZmZmd2AAB3Zmd2Zm
Znj/h2ZmZmhgAAd3dndmZmZuj/+GZmZoYAAHd3dod3dmZuj/9mZmZ2AACHd3aHd3eIiP/4ZmZmd2AAi
Hd2iIiIiI//iId2ZndgAIiIhoiIiIj//4iIiIiIYACIiId4iIiP//iIiIiIiGAAiIiIaIiI//+IiIiI
iIhkAIiIiGiIiP/4iIiIiIiIdgCIiIhoiIj/iIiIiIiIiIYAiIiIeIiIiIiIiIiIiIiGAAiIiIaP///
////////4hgAAAAAGZmZmZmZmZmZmZmYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD////////////////gA
AAf4AAAD+AAAAfgAAAHAAAABwAAAAcAAAAHAAAAAwAAAAMAAAADAAAAAwAAAAMAAAABAAAAAQAAAAEA
AAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAP4AAAH//////////////////////////w==
Description
-----------
Returns the Base64 encoded representation of the icon
.EXAMPLE
Get-Icon -Path 'C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe' -ToBase64 | Clip
Description
-----------
Returns the Base64 encoded representation of the icon and saves it to the clipboard.
.EXAMPLE
(Get-Icon -Path 'C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe' -ToBytes) -Join ''
0010103232162900002322002200040000320006400010400000128200000000000000000000000
0128001280001281280128000128012801281280012812812801921921920002550025500025525
5025500025502550255255002552552550000000000000000000000000000000000000000000000
0000000000000000000000000000000000006102102102102102102102102102102960000613611
9119119119119120136136136118000119102134102102102102102102102102102134640011810
2118102102102102102102102102102119960011810211910210413510212013613611810210496
0011810211910211125513513613613613410210496001181021031021031432481201361191021
0210396001191021031021021042552481181021021021031180011810210410210210214325513
5102102102103118001191021031181021021031432481181021021021340011911910311810210
2102232255248102102102134001191191181351191181021101432551021021021180013511911
8135119119136136255248102102102119960136119118136136136136143255136135118102119
9601361361341361361361362552551361361361361369601361361351201361361432552481361
3613613613696013613613610413613625525513613613613613613610001361361361041361362
5524813613613613613613611801361361361041361362551361361361361361361361340136136
1361201361361361361361361361361361361340813613613414325525525525525525525525524
8134000061021021021021021021021021021021020000000000000000000000000000000000000
0000000000000000000000000000000000000000000025525525525525525525525525525525525
5224003122400152240072240070007000700070003000300030003000300010001000100010000
0000000000000000000012800025400125525525525525525525525525525525525525525525525
5255255255255
Description
-----------
Returns the bytes representation of the icon. -Join was used in this for the sake
of displaying all of the data.
#>
[cmdletbinding(
DefaultParameterSetName = '__DefaultParameterSetName'
)]
Param (
[parameter(ValueFromPipelineByPropertyName=$True)]
[ValidateNotNullorEmpty()]
[string]$Path,
[parameter(ParameterSetName = 'Bytes')]
[switch]$ToBytes,
[parameter(ParameterSetName = 'Bitmap')]
[switch]$ToBitmap,
[parameter(ParameterSetName = 'Base64')]
[switch]$ToBase64
)
Begin {
If ($PSBoundParameters.ContainsKey('Debug')) {
$DebugPreference = 'Continue'
}
Add-Type -AssemblyName System.Drawing
}
Process {
$Path = Convert-Path -Path $Path
Write-Debug $Path
If (Test-Path -Path $Path) {
$Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($Path)|
Add-Member -MemberType NoteProperty -Name FullName -Value $Path -PassThru
If ($PSBoundParameters.ContainsKey('ToBytes')) {
Write-Verbose "Retrieving bytes"
$MemoryStream = New-Object System.IO.MemoryStream
$Icon.save($MemoryStream)
Write-Debug ($MemoryStream | Out-String)
$MemoryStream.ToArray()
$MemoryStream.Flush()
$MemoryStream.Dispose()
} ElseIf ($PSBoundParameters.ContainsKey('ToBitmap')) {
$Icon.ToBitMap()
} ElseIf ($PSBoundParameters.ContainsKey('ToBase64')) {
$MemoryStream = New-Object System.IO.MemoryStream
$Icon.save($MemoryStream)
Write-Debug ($MemoryStream | Out-String)
$Bytes = $MemoryStream.ToArray()
$MemoryStream.Flush()
$MemoryStream.Dispose()
[convert]::ToBase64String($Bytes)
} Else {
$Icon
}
} Else {
Write-Warning "$Path does not exist!"
Continue
}
}
}