Getting 'Invalid WMI query' with error code 0x80041017 in Windows

Getting 'Invalid WMI query' with error code 0x80041017 in Windows

"Invalid WMI query" with error code WBEM_E_INVALID_QUERY (0x80041017) found in log files or script execution when collecting Windows performance counter data.

It is possible that the Win32_PerfRawData_PerfOS_Processor cannot be found or accessed on the server and causing a null result. If the same query runs and retrieves values from other similar Windows systems at the same OS level this indicates that the query is correct and something is different at the OS level causing the query not to retrieve data.
This is a often due to a Microsoft bug.

Number: 0x80041017
Facility: WMI
Description: Invalid query when collecting Windows performance counter data

Root Cause :
The following are the possible reasons and resolution.
  1. Missing WMI classes 
      In some cases, as per KB 93113 running the following command in the Windows' command line (CMD) may solve the problem of missing WMI classes.
      %windir%\system32\wbem\wmiadap.exe /f
      This command parses all the performance libraries on the system and refreshes the Performance Counter Classes. For further details see Windows Management Instrumentation Documentation.
  2. Broken performance counters.
      Rebuild the Performance Counters using the "lodctr /r" command as per KB 185319. Additional information can be found on solution 2554336 from the Microsoft Knowledge Base.
  3. In the registry, the performance counters are disabled.

      The registry key “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\PerfProc\Performance” or “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\PerfDisk\Performance” is set so that “Disable Performance Counters” is set to 1, which means it is disabled.

      Users can manually change the registry key to "0" or they can use the Extensible Counter List Tool as described in this Microsoft blog titled "Two-Minute Drill: Disabled performance counters and Exctrlst.exe" to enable the Performance Counters in the Operating System. The registry change happens immediately.

      If the "Disable Performance Counters" registry key is not present then the Performance Counters have not been disabled at the registry key here.

      Note: AppManager Support does not provide support for problems that arise from improper modification of the registry. The Windows registry contains information critical to your computer and applications. Make sure you back up the registry before modifying it. For more information on the Windows Registry Editor and how to back up and restore it, refer to Microsoft Article ID 256986 “Description of the Microsoft Windows registry” at Microsoft Support.
  4. The columns returned by the WMI class are incomplete or unexpected. This error can indicate that the query returned a null value. Therefore the script can't continue and will throw the error code 0x80041017.
      Please contact your Microsoft support team to recreate the WMI class properly. Additional information can be found on solution 961435 from the Microsoft Knowledge Base.
      NOTE: A restart of the system may be required after applying the suggested solutions.