Powershell Get-WmiObject generic-failure

3.1k Views Asked by At

I'm struggling with a wmi query (running in Administrator Powershell) that is failing with a generic failure...

Get-WmiObject -Class win32_pnpdevice

results in:

Get-WmiObject : Generic failure At line:1 char:14
+ Get-WmiObject <<<<  -Class win32_pnpdevice
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

This happens on Windows 10 IoT, Windows 10 1809 Enterprise and Windows Embedded S7. For Windows Server 2016 the query is working fine...

I already tried repairing wmi with

net stop winmgmt
winmgmt /salvagerepository %windir%\System32\wbem
winmgmt /resetrepository %windir%\System32\wbem
net start winmgmt

and also renamed the repository folder in C:\Windows\System32\wbem and rebuild the repository. But the query is still not working.

Calling the query via python brings some more error codes:

>>> import wmi
>>> w = wmi.WMI()
>>> pnp = w.Win32_PnPDevice()
Traceback (most recent call last):
  File "C:\Users\Engineering\AppData\Local\Programs\Python\Python37\lib\site-packages\wmi.py", line 880, in query
    return self._namespace.query(wql, self, fields)
  File "C:\Users\Engineering\AppData\Local\Programs\Python\Python37\lib\site-packages\wmi.py", line 1072, in query
    return [ _wmi_object(obj, instance_of, fields) for obj in self._raw_query(wql) ]
  File "C:\Users\Engineering\AppData\Local\Programs\Python\Python37\lib\site-packages\wmi.py", line 1072, in <listcomp>
    return [ _wmi_object(obj, instance_of, fields) for obj in self._raw_query(wql) ]
  File "C:\Users\Engineering\AppData\Local\Programs\Python\Python37\lib\site-packages\win32com\client\dynamic.py", line 236, in __getitem__
    return self._get_good_object_(self._enum_.__getitem__(index))
  File "C:\Users\Engineering\AppData\Local\Programs\Python\Python37\lib\site-packages\win32com\client\util.py", line 37, in __getitem__
    return self.__GetIndex(index)
  File "C:\Users\Engineering\AppData\Local\Programs\Python\Python37\lib\site-packages\win32com\client\util.py", line 53, in __GetIndex
    result = self._oleobj_.Next(1)
pywintypes.com_error: (-2147217407, 'OLE error 0x80041001', None, None)

Any ideas?

1

There are 1 best solutions below

0
On
  • Windows 7 x64

I've tried almost everything here and there to fix it, but nothing works from what I've found. The wbemtest is returned the same text plus error 0x80041001. Nor WMI service restart or WMI repository reset. Nor numerious MSDN forums.

Nor performance counters restore:

https://community.progress.com/s/article/WMI-Based-Active-Monitors-fail-with-error-Generic-Failure-or-Invalid-Query

Resolution

When you get a Generic Failure or Invalid Query, but there doesn't seem to be an issue with the query, it is often the case that there is an issue with a Performance Monitor counter, or its availability on the device you are monitoring.

To create the necessary counters:

  • Open an elevated Command Prompt (Right click and select Run as Administrator)

  • For 64-bit Operating Systems, enter the following two commands; for 32-bit Operating Systems, just enter the first command below:

    %WINDIR%\system32\lodctr /R
    %WINDIR%\SysWow64\lodctr /R
    
  • Once you have done this, open Performance Monitor again, and confirm that the counters are now available

In the next I've found this:

http://www.nullskull.com/q/81326/remote-wmi--generic-failure-0x80041001.aspx

And tried to run:

wmic /node:'randomtext' path win32_Product get name

The command and output is not related to the issue, but the error in the Event Log got an accidental direction to search:

windows event DCOM 10009

And found this:

http://forum.oszone.net/post-1276605.html#post1276605

Where the registry key is mentioned:

HKCU\Printers\Connections\<computer name>\<Printer>`

Then I've tried to start the Print Spooler service and it worked out:

net start Spooler

I have no idea how is it connected to the issue.