locked
Unable to set Powerplans with PowerShell post 1809 RRS feed

  • Question

  • I could use some help...I have lost the ability to set my Powerplans.  I have a few custom plans I have been using powershell to set in my environment,  In 1607 I used the following code. It stopped working in 1809

    $action = get-wmiobject -NS root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = 'Custom Plan Name'" -ErrorAction Stop
    $action.Activate()

    Now if i use the code below on a machine thats been upgraded from 1607 to 1809 it works.  But a fresh install of 1809 the code blow doesn't work.  Looks like in 1809 there don't seem to be a MethodName "Activate" any longer.

    	$power3 = Get-CimInstance -Namespace "root\cimv2\power" -class Win32_PowerPlan -filter "ElementName = 'Custom Plan Name'"
    	
    	
    	Invoke-CimMethod -InputObject $power3 -MethodName Activate




    • Edited by GQed76 Thursday, January 9, 2020 5:52 PM
    Thursday, January 9, 2020 5:49 PM

All replies

  • Sorry but this is not a scripting issue. It appears you have system problems or that your installs are corrupt. BIOS settings can effect powerplan and a non-compliant BIOS will likely work incorrectly.

    After an upgrade any custom plans may be lost and you would have to recreate them.  Contact MS Support for any issues with how this works.

    To test to see what plans are available do the following:

    Get-CimInstance -Namespace root\cimv2\power -class Win32_PowerPlan


    \_(ツ)_/

    Thursday, January 9, 2020 6:51 PM
  • Thanks for the quick reply.  I've been looking into this for better part of a day.

    It looks like Microsoft removed the MethodName Activate in later Win10 Builds."https://github.com/ansible/ansible/issues/43827#issuecomment-413359051

    Get-CimInstance-Namespace root\cimv2\power -Class win32_PowerPlan |Get-Method

     
    While, if you use WMI instead of CIM the method does exist:

     Get-WmiObject -Namespace root\cimv2\power -Class win32_PowerPlan | Get-Member

       TypeName: System.Management.ManagementObject#root\cimv2\power\Win32_PowerPlan

    Activate is there, but it also no longer works

      
    JV


    • Edited by GQed76 Thursday, January 9, 2020 8:15 PM
    Thursday, January 9, 2020 8:14 PM
  • Ther is no such command as Get-Method. Perhaps take time to learn PowerShell or call MS> MS did not remove anything. You need to learn how the CmdLets and WMI/CIM work and understand what I posted above. Stop guessing as it is just adding more confusion to your understranding of these technologies.


    \_(ツ)_/


    • Edited by jrv Thursday, January 9, 2020 9:14 PM
    Thursday, January 9, 2020 9:14 PM
  • Well I guess your reputation is well earned. Too bad


    JV

    Thursday, January 9, 2020 9:24 PM
  • Well - I can only point out what you show me. If you do not wish to learn PowerShell then you likely will not understand the answer I post5ed.

    I am on 1903 and have tested on 1809.

    PS C:\scripts> $x = Get-WmiObject -Namespace root\cimv2\power -Class win32_PowerPlan
    PS C:\scripts> $x[0].activate
    
    OverloadDefinitions
    -------------------
    System.Management.ManagementBaseObject Activate()
    
    
    
    PS C:\scripts>

    The method is clearly there.  The issue is that you do not understand CIM or PowerShell and are just guessing.  Take some time to look up these things.  If you knew what you were doing you would know that blaming it on Microsoft by claiming someone removed a method was a completely idiotic statement.  It just doesn't make any technical sense and anyone with basic computer training would see that or would know how to etermine what has changed on any new release.  It is all documented on the MS site.

    Always start by doing your homework meaning read the documentation for the WMI/CIM class and the full help for any CmdLet that you do not know how to use.  This is just junior tech 101 rules.

    My bet is that you don't ev3en know how to look up a CIM class or how to read the technical document.

    Start practicing on this class.  It will help you in the future.

    https://docs.microsoft.com/en-us/previous-versions/windows/desktop/powerwmiprov/win32-powerplan

    Once you learn basic technology and how to work with it all of this will be obvious and you will do these things quickly and without thinking about them.


    \_(ツ)_/

    Thursday, January 9, 2020 9:36 PM