Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to handle error from unsupported WMI query?

$
0
0
    $deviceid = (gwmi win32_logicaldisk -filter "Name='$drvltr'").`
        GetRelated('Win32_DiskPartition').GetRelated('Win32_DiskDrive') | 
        foreach { $_.PNPDeviceID }
    $predict = gwmi -Namespace root\wmi -class MSStorageDriver_FailurePredictStatus | 
        Where-Object { $_.InstanceName -like "$deviceid*" } | foreach { $_.PredictFailure }

I use the above code to get PredictFailure status for each volume as part of an inventory script.  The problem is not all drives support SMART.  What is the best way to test/handle this to avoid throwing an error?

The error I get is this:

gwmi : Not supported... $Predict = gwmi -Namespace root\wmi -class MSStorageDriver_FailurePredictStatus... +CategoryInfo : Invalid Operation [Get-WmiObject], ManagementException..


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>