1
1
<#
2
- Check (and recurse) current directory .\CheckSignature.ps1
3
- Check directory after MSI install .\CheckSignature.ps1 -MsiInstall
4
- Check directory after gallery install .\CheckSignature.ps1 -GalleryInstall
2
+ Check (and recurse) current directory .\CheckSignature.ps1
3
+ Find and check directory of Azure PowerShell modules .\CheckSignature.ps1 -AzurePowerShell
4
+ Check directory of MSI-installed modules .\CheckSignature.ps1 -MsiInstall
5
+ Check directory of gallery-installed modules .\CheckSignature.ps1 -GalleryInstall
6
+ Check files in provided path .\CheckSignature.ps1 -CustomPath $Path
5
7
#>
6
8
[CmdletBinding (DefaultParameterSetName = " CurrentDirectory" )]
7
9
Param
8
10
(
11
+ [Parameter (ParameterSetName = " AzurePowerShell" , Mandatory = $true )]
12
+ [switch ]$AzurePowerShell ,
9
13
[Parameter (ParameterSetName = " MsiInstall" , Mandatory = $true )]
10
14
[switch ]$MsiInstall ,
11
15
[Parameter (ParameterSetName = " GalleryInstall" , Mandatory = $true )]
@@ -37,9 +41,15 @@ function Check-All {
37
41
[CmdletBinding ()]
38
42
param ([Parameter ()][string ]$path )
39
43
44
+ if (! (Get-Command " sn.exe" - ErrorAction SilentlyContinue))
45
+ {
46
+ Write-Error " Unable to find sn.exe; please ensure that the Windows SDK is installed and found in the PATH environment variable."
47
+ return
48
+ }
49
+
40
50
$invalidList = @ ()
41
51
42
- $files = Get-ChildItem $path \* - Include * .dll - Recurse | where { $_.FullName -like " *Azure*" }
52
+ $files = Get-ChildItem $path \* - Include * .dll - Recurse | Where-Object { $_.FullName -like " *Azure*" }
43
53
Write-Host " Checking the strong name signature of $ ( $files.Count ) files (.dll)" - ForegroundColor Yellow
44
54
45
55
$invalidStrongNameList = @ ()
@@ -60,11 +70,11 @@ function Check-All {
60
70
61
71
# -------------------------------------
62
72
63
- $files = Get-ChildItem $path \* - Include * .dll, * .ps1, * .psm1 - Recurse | where { $_.FullName -like " *Azure*" }
64
- $files = $files | where { ($_.FullName -notlike " *Newtonsoft.Json*" ) -and `
65
- ($_.FullName -notlike " *AutoMapper*" ) -and `
66
- ($_.FullName -notlike " *Security.Cryptography*" ) -and `
67
- ($_.FullName -notlike " *BouncyCastle.Crypto*" )}
73
+ $files = Get-ChildItem $path \* - Include * .dll, * .ps1, * .psm1 - Recurse | Where-Object { $_.FullName -like " *Azure*" }
74
+ $files = $files | Where-Object { ($_.FullName -notlike " *Newtonsoft.Json*" ) -and `
75
+ ($_.FullName -notlike " *AutoMapper*" ) -and `
76
+ ($_.FullName -notlike " *Security.Cryptography*" ) -and `
77
+ ($_.FullName -notlike " *BouncyCastle.Crypto*" )}
68
78
Write-Host " Checking the authenticode signature of $ ( $files.Count ) files (.dll, .ps1, .psm1)" - ForegroundColor Yellow
69
79
70
80
$invalidAuthenticodeList = @ ()
@@ -91,14 +101,102 @@ function Check-All {
91
101
92
102
$path = " .\"
93
103
94
- if ($PSCmdlet.ParameterSetName -eq " MsiInstall " )
104
+ if ($PSCmdlet.ParameterSetName -eq " AzurePowerShell " )
95
105
{
96
- $path = " ${env: ProgramFiles(x86)} \Microsoft SDKs\Azure\PowerShell"
106
+ $ProfileModule = Get-Module - Name AzureRM.Profile - ListAvailable
107
+ if (! ($ProfileModule ))
108
+ {
109
+ Write-Error " Unable to find the AzureRM.Profile module. Please ensure that Azure PowerShell has been installed and the appropriate path is found in the PSModulePath environment variable."
110
+ return
111
+ }
112
+
113
+ if ($ProfileModule.Count -gt 1 )
114
+ {
115
+ Write-Error " Mulitple versions of Azure PowerShell were found. Please use the -MsiInstall and -GalleryInstall switches to select the installed version you want to check."
116
+ return
117
+ }
118
+
119
+ $ModulePath = $ProfileModule.Path
120
+ if ($ModulePath -like " *Microsoft SDKs\Azure\PowerShell*" )
121
+ {
122
+ $EndIdx = $ModulePath.IndexOf (" PowerShell\ResourceManager" , [System.StringComparison ]::OrdinalIgnoreCase) + " PowerShell" .Length
123
+ }
124
+ elseif ($ModulePath -like " *Modules\AzureRM.Profile*" )
125
+ {
126
+ $EndIdx = $ModulePath.IndexOf (" Modules\AzureRM.Profile" , [System.StringComparison ]::OrdinalIgnoreCase) + " Modules" .Length
127
+ }
128
+
129
+ $path = $ModulePath.Substring (0 , $EndIdx )
130
+ Write-Host " Found AzureRM module - checking all (Azure) files in $path " - ForegroundColor Yellow
131
+ }
132
+ elseif ($PSCmdlet.ParameterSetName -eq " MsiInstall" )
133
+ {
134
+ $ProfileModule = Get-Module - Name AzureRM.Profile - ListAvailable
135
+ if (! ($ProfileModule ))
136
+ {
137
+ Write-Error " Unable to find the AzureRM.Profile module. Please ensure that Azure PowerShell has been installed and the appropriate path is found in the PSModulePath environment variable."
138
+ return
139
+ }
140
+
141
+ $SearchString = " Microsoft SDKs\Azure\PowerShell"
142
+
143
+ $ModulePath = $ProfileModule.Path
144
+
145
+ if ($ProfileModule.Count -gt 1 )
146
+ {
147
+ $ModulePath = $ProfileModule | Where-Object { $_.Path -like " *$ ( $SearchString ) *" }
148
+ if (! ($ModulePath ))
149
+ {
150
+ Write-Error " Unable to find path of MSI-installed modules from multiple locations found in PSModulePath."
151
+ return
152
+ }
153
+ }
154
+ else
155
+ {
156
+ if ($ModulePath -notlike " *$ ( $SearchString ) *" )
157
+ {
158
+ Write-Error " Modules installed on the current machine were not from MSI. Consider using the -GalleryInstall switch."
159
+ return
160
+ }
161
+ }
162
+
163
+ $EndIdx = $ModulePath.IndexOf (" PowerShell\ResourceManager" , [System.StringComparison ]::OrdinalIgnoreCase) + " PowerShell" .Length
164
+ $path = $ModulePath.Substring (0 , $EndIdx )
97
165
Write-Host " Installed Azure PowerShell from MSI - checking all (Azure) files in $path " - ForegroundColor Yellow
98
166
}
99
167
elseif ($PSCmdlet.ParameterSetName -eq " GalleryInstall" )
100
168
{
101
- $path = " $ ( $env: ProgramFiles ) \WindowsPowerShell\Modules"
169
+ $ProfileModule = Get-Module - Name AzureRM.Profile - ListAvailable
170
+ if (! ($ProfileModule ))
171
+ {
172
+ Write-Error " Unable to find the AzureRM.Profile module. Please ensure that Azure PowerShell has been installed and the appropriate path is found in the PSModulePath environment variable."
173
+ return
174
+ }
175
+
176
+ $SearchString = " WindowsPowerShell\Modules"
177
+
178
+ $ModulePath = $ProfileModule.Path
179
+
180
+ if ($ProfileModule.Count -gt 1 )
181
+ {
182
+ $ModulePath = $ProfileModule | Where-Object { $_.Path -like " *$ ( $SearchString ) *" }
183
+ if (! ($ModulePath ))
184
+ {
185
+ Write-Error " Unable to find path of gallery-installed modules from multiple locations found in PSModulePath."
186
+ return
187
+ }
188
+ }
189
+ else
190
+ {
191
+ if ($ModulePath -notlike " *$ ( $SearchString ) *" )
192
+ {
193
+ Write-Error " Modules installed on the current machine were not from the gallery. Consider using the -MsiInstall switch."
194
+ return
195
+ }
196
+ }
197
+
198
+ $EndIdx = $ModulePath.IndexOf (" Modules\AzureRM.Profile" , [System.StringComparison ]::OrdinalIgnoreCase) + " Modules" .Length
199
+ $path = $ModulePath.Substring (0 , $EndIdx )
102
200
Write-Host " Installed Azure PowerShell from the gallery - checking all (Azure) files in $path " - ForegroundColor Yellow
103
201
}
104
202
elseif ($PSCmdlet.ParameterSetName -eq " CustomPath" )
0 commit comments