Skip to content

Commit 8ec143e

Browse files
committed
Added a try catch to first WMI call in the 'ByComputerName' parameter set. If the call fails the entire loop for that system will be terminated.
1 parent 1745e61 commit 8ec143e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Functions/Test-WannaCryVulnerability.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
.ProjectUri
1212
https://github.com/dotps1/PSFunctions
1313
.ReleaseNotes
14-
Adding FullName for type Microsoft.Management.Infrastructure.CimSession, else Windows 8.1/WMF 5.0 cannot find the type.
14+
Added a try catch to first WMI call in the 'ByComputerName' parameter set. If the call fails the entire loop for that system will be terminated.
1515
1616
#>
1717

@@ -87,7 +87,7 @@ param (
8787
[Parameter(
8888
ParameterSetName = "ByComputerName"
8989
)]
90-
[PSCredential]
90+
[System.Management.Automation.PSCredential]
9191
$Credential = [PSCredential]::Empty,
9292

9393
[Parameter(
@@ -151,15 +151,15 @@ process {
151151
}
152152

153153
try {
154-
$osCaption = Get-WmiObject -ComputerName $nameValue -Class Win32_OperatingSystem -Property Caption -Credential $Credential |
154+
$osCaption = Get-WmiObject -ComputerName $nameValue -Class Win32_OperatingSystem -Property Caption -Credential $Credential -ErrorAction Stop |
155155
Select-Object -ExpandProperty Caption
156156
} catch {
157-
Write-Error $_.ToString()
157+
Write-Error -Message "Failed to contact WMI on '$nameValue'." -RecommendedAction "Verify WS-MAN is not being blocked by the firewall."
158158
continue
159159
}
160160

161161
if ($osCaption -match "Windows 10|2016") {
162-
Write-Error -Message "$osCaption is not vulnerable to WannaCry."
162+
Write-Warning -Message "$osCaption is not vulnerable to WannaCry."
163163
continue
164164
}
165165

0 commit comments

Comments
 (0)