win32_PowerSettingDataIndex

This topic contains 8 replies, has 2 voices, and was last updated by Profile photo of James Orlando James Orlando 1 year, 9 months ago.

  • Author
    Posts
  • #22563
    Profile photo of James Orlando
    James Orlando
    Participant

    Any idea why this would not work on Windows 7 but does work on 8.1?

    Get-WmiObject -Namespace root\cimv2\power -Class win32_PowerSettingDataIndex

    Using wbemtest that is a valid class on both operating systems?

    Here is the full error:
    PS C:\Windows\system32> Get-WmiObject -Namespace root\cimv2\power -Class win32_PowerSettingDataIndex
    Get-WmiObject :
    At line:1 char:1
    + Get-WmiObject -Namespace root\cimv2\power -Class win32_PowerSettingDataIndex
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    PS C:\Windows\system32>

    Thanks for helping a powershell rookie!

  • #22566
    Profile photo of Don Jones
    Don Jones
    Keymaster

    It looks like WMI barfed. Possibly the machine you're querying doesn't expose that information, even though the OS is capable of it.

  • #22569
    Profile photo of James Orlando
    James Orlando
    Participant

    I deployed this as part of a script... it barfed on 17,000+ Windows 7 machines. Its only running on the Windows 8+ desktops.

  • #22570
    Profile photo of Don Jones
    Don Jones
    Keymaster

    That would strongly suggest Win7 isn't implementing it, or isn't abLe to read from the associated hardware.

  • #22571
    Profile photo of James Orlando
    James Orlando
    Participant

    Thats the first thing I checked. Using wbemtest the namespace is there. I am still digging but there is a change a group policy object may be preventing access to the namespace. Have you heard of anything like that?

  • #22584
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Well, usually permissions problems would generate a more specific error.

    Using Webemtest to check that the namespace or class exists isn't really a valid test. A class exists whether there's underlying components or not; Win32_TapeDrive exists, but I doubt you have tape drives attached. Have you tried querying any actual instances in Wbemtest?

    It's the error message I'm looking at. If the class merely didn't exist, you'd get an entirely different error.

    Can you query instances locally on one of the non-working machines? Can you query instances using Wbemtest? What about using Get-CimInstance, both locally and remote (requires WS-MAN to be enabled if you're trying remotely)?

  • #22590
    Profile photo of James Orlando
    James Orlando
    Participant

    get-ciminstance works on windows 8 but also errors on my windows 7 boxes.

    PS C:\Windows\system32> get-ciminstance -Namespace root\cimv2\power -ClassName win32_powersettingdataindex
    get-ciminstance : This program is blocked by group policy. For more information, contact your system administrator.
    At line:1 char:1
    + get-ciminstance -Namespace root\cimv2\power -ClassName win32_powersettingdataind ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (root\cimv2\powe...ettingdataindex:String) [Get-CimInstance], CimException
    + FullyQualifiedErrorId : HRESULT 0x800704ec,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand

    I did find that if I moved the windows 7 machine to an OU with fewer group policies then get-wmiobject works. So, one of my GPO's must be blocking it....

  • #22597
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Win7 machines probably have PowerShell v2, so CIM isn't present, then. Good to know.

  • #22610
    Profile photo of James Orlando
    James Orlando
    Participant

    Thanks for the help. Ultimately what I did was change from:
    ##Native Sleep Policy Check

    $activeplan = Get-WmiObject -Namespace root\cimv2\power -Class win32_PowerPlan -Filter "isActive='true'"
    $activeplan = $activeplan.InstanceID
    $activeplan = $activeplan.TrimStart("Microsfot:PowerPlan\{_")
    $activeplan = $activeplan.Trim([char]0x007D)
    $ACSleepplan = Get-WmiObject -Namespace root\cimv2\power -Class win32_PowerSettingDataIndex | Where-Object {$_.InstanceID -like "*$activeplan*\AC\{29f6c1db-86da-48c5-9fdb-f2b67b1f44da}"}
    $SleepSetting = $ACSleepplan.SettingIndexValue

    $SleepSetting | Echo

    to:

    #Native Sleep Policy Check
    $powerplan=get-wmiobject -namespace "root\cimv2\power" -class Win32_powerplan | where {$_.IsActive}
    $instanceid = $powerplan.InstanceID
    $instanceid = $instanceid.TrimStart("Microsfot:PowerPlan\")

    $powerSettings = $powerplan.GetRelated("win32_powersettingdataindex") | Where-Object {$_.InstanceID -like "*$instanceid*\AC\{29f6c1db-86da-48c5-9fdb-f2b67b1f44da}"}

    $powerSettings.SettingIndexValue | Echo

    Using getrelated I was able to obtain the data I was looking for. There may have been ten better ways of doing this but I am enjoying becoming familiar with powershell.

    Thanks Don!

    James

You must be logged in to reply to this topic.