On one of our production servers, I started to get an error while running our scripts. Stripping down the code, I receive the error when running this command from the PowerShell prompt:
Get-WmiObject -Class win32_volume
The result is this:
Get-WmiObject :
At line:1 char:14
+ Get-WmiObject <<<< -Class win32_volume
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
What's noticable to me is that there's no description of the error on the first line of the result. This script has worked in the past, and continues to work on our other servers.
I'm running this as an administrator on the server, and the PowerShell session is in administrator mode. Any suggestions about what to do to solve this?
Thanks.
If Get-WmiObject is used on a remote computer, the job is created on the local computer, and the results from remote computers are automatically returned to the local computer.
Use the try block to define a section of a script in which you want PowerShell to monitor for errors. When an error occurs within the try block, the error is first saved to the $Error automatic variable. PowerShell then searches for a catch block to handle the error.
How to Code PowerShell Error Handling. There are three big steps to writing error handling in PowerShell: first is to identify where an error may occur: which command. Then, you put that command inside a try { } block. Third, you put inside a catch { } block what should be done if the error happens.
We had this error and WMI had crashed without giving any indications that it had done so- restarting it solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With