Skip to content

Commit 0beeab9

Browse files
committed
Replaced Write-Warning with Write-Error so it can be caught in a try catch block.
1 parent fb89117 commit 0beeab9

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

Functions/Test-WannaCryVulnerability.ps1

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<#PSScriptInfo
22
33
.Version
4-
2.0
4+
2.1
55
.Guid
66
477aa3f4-0434-4925-9c92-7323066cceb7
77
.Author
@@ -11,8 +11,7 @@
1111
.ProjectUri
1212
https://github.com/dotps1/PSFunctions
1313
.ReleaseNotes
14-
Per Lee Holmes (@lee_holmes) there is still a needed patch for Windows 10 1607 and prior https://twitter.com/Lee_Holmes/status/864604299405410304. Added Operating System Version to returned object.
15-
14+
Replaced Write-Warning with Write-Error so it can be caught in a try catch block.
1615
#>
1716

1817
<#
@@ -42,7 +41,7 @@
4241
OperatingSystemCaption : Microsoft Windows 7 Professional
4342
OperatingSystemVersion : 6.1.7601
4443
Vulnerable : False
45-
AppliedHotFixIds : KB4012212|KB4015546|KB4015549
44+
AppliedHotFixID : KB4012212|KB4015546|KB4015549
4645
SMB1FeatureEnabled : False
4746
SMB1ProtocolEnabled : False
4847
.Example
@@ -52,7 +51,7 @@
5251
OperatingSystemCaption : Microsoft Windows 7 Professional
5352
OperatingSystemVersion : 6.1.7601
5453
Vulnerable : True
55-
AppliedHotFixIds :
54+
AppliedHotFixID :
5655
SMB1FeatureEnabled : False
5756
SMB1ProtocolEnabled : True
5857
.Notes
@@ -154,13 +153,13 @@ process {
154153
}
155154

156155
if ([Version]$osInformation.Version -ge [Version]"10.0.15063") {
157-
Write-Warning -Message "$($osInformation.Caption) $($osInformation.Version) is not vulnerable to the WannaCry Exploit."
156+
Write-Error -Message "$($osInformation.Caption) $($osInformation.Version) is not vulnerable to the WannaCry Exploit."
158157
continue
159158
}
160159

161160
# HotFixes
162161
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using WMI" -CurrentOperation "Inventory hotfix information" -PercentComplete 40
163-
$appliedHotFixIds = (Get-WmiObject -ComputerName $nameValue -Class Win32_QuickFixEngineering -Credential $Credential).Where({
162+
$appliedHotFixID = (Get-WmiObject -ComputerName $nameValue -Class Win32_QuickFixEngineering -Credential $Credential).Where({
164163
$_.HotFixID -in $hotFixIDs
165164
}).HotFixID
166165

@@ -188,7 +187,7 @@ process {
188187

189188
# Vulnerable?
190189
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using WMI" -CurrentOperation "Determine vulnerability status" -PercentComplete 100
191-
if ($appliedHotFixIds.Count -gt 0 -and -not $smb1FeatureEnabled -and -not $smb1ProtocolEnabled) {
190+
if ($appliedHotFixId.Count -gt 0 -and -not $smb1FeatureEnabled -and -not $smb1ProtocolEnabled) {
192191
$vulnerable = $false
193192
} else {
194193
$vulnerable = $true
@@ -199,7 +198,7 @@ process {
199198
OperatingSystemCaption = $osInformation.Caption
200199
OperatingSystemVersion = $osInformation.Version
201200
Vulnerable = $vulnerable
202-
AppliedHotFixIds = $appliedHotFixIds -join "|"
201+
AppliedHotFixID = $appliedHotFixId -join "|"
203202
SMB1FeatureEnabled = $smb1FeatureEnabled
204203
SMB1ProtocolEnabled = $smb1ProtocolEnabled
205204
}
@@ -220,7 +219,7 @@ process {
220219

221220
# HotFixes
222221
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using CIM" -CurrentOperation "Inventory hotfix information" -PercentComplete 40
223-
$appliedHotFixIds = (Get-CimInstance -CimSession $CimSession -ClassName Win32_QuickFixEngineering).Where({
222+
$appliedHotFixID = (Get-CimInstance -CimSession $CimSession -ClassName Win32_QuickFixEngineering).Where({
224223
$_.HotFixID -in $hotFixIDs
225224
}).HotFixID
226225

@@ -249,7 +248,7 @@ process {
249248

250249
# Vulnerable?
251250
Write-Progress -Activity "Testing '$nameValue' for WannaCry vulnerabilities using CIM" -CurrentOperation "Determine vulnerability status" -PercentComplete 100
252-
if ($appliedHotFixIds.Count -gt 0 -and -not $smb1FeatureEnabled -and -not $smb1ProtocolEnabled) {
251+
if ($appliedHotFixId.Count -gt 0 -and -not $smb1FeatureEnabled -and -not $smb1ProtocolEnabled) {
253252
$vulnerable = $false
254253
}
255254

@@ -258,7 +257,7 @@ process {
258257
OperatingSystemCaption = $osInformation.Caption
259258
OperatingSystemVersion = $osInformation.Version
260259
Vulnerable = $vulnerable
261-
AppliedHotFixIds = $appliedHotFixIds -join "|"
260+
AppliedHotFixID = $appliedHotFixId -join "|"
262261
SMB1FeatureEnabled = $smb1FeatureEnabled
263262
SMB1ProtocolEnabled = $smb1ProtocolEnabled
264263
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ PSComputerName : myrig
250250
OperatingSystemCaption : Microsoft Windows 7 Professional
251251
OperatingSystemVersion : 6.1.7601
252252
Vulnerable : False
253-
AppliedHotFixIds : KB4012212|KB4015546|KB4015549
253+
AppliedHotFixID : KB4012212|KB4015546|KB4015549
254254
SMB1FeatureEnabled : False
255255
SMB1ProtocolEnabled : False
256256
@@ -261,7 +261,7 @@ PSComputerName : workstation
261261
OperatingSystemCaption : Microsoft Windows 7 Professional
262262
OperatingSystemVersion : 6.1.7601
263263
Vulnerable : True
264-
AppliedHotFixIds :
264+
AppliedHotFixID :
265265
SMB1FeatureEnabled : False
266266
SMB1ProtocolEnabled : True
267267
```

0 commit comments

Comments
 (0)