Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get-WMIObject returns an error without a description

Tags:

powershell

wmi

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.

like image 563
Moskie Avatar asked Aug 01 '11 17:08

Moskie


People also ask

What does Get WmiObject return?

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.

How to capture errors in PowerShell script?

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 add error handling in PowerShell?

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.


1 Answers

We had this error and WMI had crashed without giving any indications that it had done so- restarting it solved the problem.

like image 115
topcav Avatar answered Oct 09 '22 20:10

topcav