2

How do I get this Powershell command working? Does this mean something on my non-working machine is corrupted? What would be some steps to solve?

Command on non-working/broken machine:

PS> Get-CimInstance -Class "Win32_PowerPlan" -Namespace "root\cimv2\power"

Get-CimInstance : invalid class
At line:1 char:1
+ Get-CimInstance -Class "Win32_PowerPlan" -Namespace "root\cimv2\power ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo            : MetadataError: (root\cimv2\power:win32_PowerPlan:String) [Get-CimInstance, CimException
    + FullyQualifiedErrorId   : HRESULT 0x80041010,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand

Command on working machine:

PS> Get-CimInstance -Class "Win32_PowerPlan" -Namespace "root\cimv2\power"

Caption        :
Description    : Automatically balances performance with energy consumption on capable hardware.
ElementName    : Balanced
InstanceID     : Microsoft:PowerPlan\{1234-guid-abc-1}
IsActive       : True
PSComputerName :

Caption        :
Description    : Favors performance, but may use more energy.
ElementName    : High performance
InstanceID     : Microsoft:PowerPlan\{1234-guid-abc-2}
IsActive       : False
PSComputerName :

Caption        :
Description    : Saves energy by reducing your computer’s performance where possible.
ElementName    : Power saver
InstanceID     : Microsoft:PowerPlan\{1234-guid-abc-3}
IsActive       : False
PSComputerName :

Caption        :
Description    : Provides ultimate performance on higher end PCs.
ElementName    : Ultimate Performance
InstanceID     : Microsoft:PowerPlan\{1234-guid-abc-4}
IsActive       : False
PSComputerName :
satoukum
  • 1,188
  • 1
  • 21
  • 31
  • What is the PowerShell version on the not-working machine? Perhaps try `Get-WmiObject` on that computer instead of `Get-CimInstance` – Theo Jul 22 '21 at 20:26
  • Non-working machine: PowerShell 5.1.14393.4530 The real command that is failing is from a dsc module script that I run on 1000+ machines. PowershellModule is in ComputerManagementDSC and command is ```Get-CimInstance -Query "SELECT * FROM Win32_PowerPlan WHERE ElementName = 'High performance'" -QueryDialect "WQL" -Namespace "root\cimv2\power"``` – satoukum Jul 22 '21 at 20:33
  • Note: ```Get-WmiObject -Class "Win32_PowerPlan" -Namespace "root\cimv2\power"``` fails with the invalid class error on the non-working machine as well. Works fine on the working machine. – satoukum Jul 22 '21 at 20:38
  • Also, make sure you are [**running as an admin**](https://stackoverflow.com/a/70823056/1366033) – KyleMit Jan 23 '22 at 15:40

1 Answers1

3

Solution was to rebuild the WMI repository.

At first I followed instructions online to rebuild from MOF files, but those didn't work, so I made a backup of the repository and then copied over a working repository from another machine.

Location: C:\Windows\System32\wbem\repository

satoukum
  • 1,188
  • 1
  • 21
  • 31