Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Try {
$CimSession = New-CimSession -ComputerName $Computer -ErrorAction Stop
}
Catch {
Clear-Variable EV -ErrorAction SilentlyContinue
$CimSession = New-CimSession -ComputerName $Computer -SessionOption (New-CimSessionOption -Protocol Dcom) -ErrorAction SilentlyContinue -ErrorVariable EV
}
If ($EV)
{ Write-Warning "$($Computer): Unable to connect because ""$($Error[0])"""
Continue
}
Try {
$Disks = Get-CimInstance Win32_LogicalDisk -Filter "DriveType = 3" -CimSession $CimSession -ErrorAction Stop
}
Catch {
Write-Warning "$($Computer): Unable to retrieve disk information because ""$($Error[0])"""
Continue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment