3

I'm trying to return the Win32_PowerPlan in PowerShell 7 on Windows 11 with the following code:

get-wmiobject -namespace "root\cimv2\power" -class Win32_powerplan

However, I get the output:

get-wmiobject : 
At line:1 char:1
+ get-wmiobject -namespace "root\cimv2\power" -class Win32_powerplan
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Error Log Outuput

Not sure what could be going on or how to get better error logs. The official docs use this exact code snippet, so not sure what it should change to if it's wrong.

Potentially related to PowerShell call to Win32_PowerPlan showing invalid class error

KyleMit
  • 30,350
  • 66
  • 462
  • 664
  • 1
    `Get-WmiObject` isn't available in PowerShell core. Either run it in Windows PowerShell, or use `Get-CimInstance` as they are the cmdlets that superseded it. – Abraham Zinala Jan 23 '22 at 14:27
  • 2
    As an aside: The CIM cmdlets (e.g., `Get-CimInstance`) superseded the WMI cmdlets (e.g., `Get-WmiObject`) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell (Core) v6+, where all future effort will go, doesn't even _have_ them anymore. Note that WMI still _underlies_ the CIM cmdlets, however. For more information, see [this answer](https://stackoverflow.com/a/54508009/45375). – mklement0 Jan 23 '22 at 14:28

1 Answers1

2

It would appear that, to retrieve the information you are seeking, PowerShell needs to be run in "elevated" mode (i.e., "Run as Administrator").

When doing so, I see the information as intended; however, when running 'normally' (even though I'm logged on with admin rights), I see the same error message that you have reported.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83