Change and Restore Power Plan during TS

Ok, so this is old news. You change your Power Plan to High Performance during your TS to speed up the process.  So maybe you did that for a software upgrade (office, or Win10 Build upgrade), and then your user complained that the power settings were different than how they had configured it.

How about you grab the current power plan, put that in a TS Variable for later, change your power plan to High Performance, then after all your work is done, set the Power Plan back to the original plan using that TS Variable… that sounds good right?

So what does this look like in the TS?  2 Groups, 5 steps (No content required)

image

  1. Group 1 - Power Settings Change (no conditions on Group)
    1. Set TS Var "PowerPlan" to WMI's Active PowerPlan
      Code: powershell.exe -executionpolicy bypass -command "& {$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value('PowerPlan') = (Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power -Filter {isActive='true'} -EA silentlyContinue).elementname}"
      image
    2. Record Current Plan in SMSTS log (This writes the Current plan into the log file.) – This step is Optional. I just like to have that info in the SMSTS log for troubleshooting.
      Code: powershell.exe -executionpolicy bypass -command "& {$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value('PowerPlan')}" –verbose
      image
    3. Set Power Options - High Performance
      Condition: Task Sequence Variable PowerPlan not equals High performance
      imageCode: PowerCfg.exe /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
      image
  2. Group 2: Power Settings Restore (only runs if computer originally had something different than High Performance set)
    Conditions: Task Sequence Variable PowerPlan not equals High Performance

    1. Set Power Options - Balanced
      Conditions: Task Sequence Variable PowerPlan equals Balanced
      image
      Code: PowerCfg.exe /s a1841308-3541-4fab-bc81-f71556f20b4a
      image
    2. Set Power Options - Power saver
      Conditions: Task Sequence Variable PowerPlan equals Power saver
      image
      Code: PowerCfg.exe /s a1841308-3541-4fab-bc81-f71556f20b4a
      image

And that’s it.  Now, just like your parents always told you, put things back when you’re done.

To watch this in progress, check out this video.  Here I test starting on each of the 3 power plans, for Power saver & Balanced, you'll see it change to High performance, and back. When starting with High performance, it stays consistent for the entire TS.

Thanks to @PotentEngineer for the info to get me over the hump:
http://www.potentengineer.com/using-powershell-to-set-osd-task-sequence-variables/

2 thoughts on “Change and Restore Power Plan during TS

  • September 13, 2017 at 7:13 am
    Permalink

    I really like the post and am testing it in our OS upgrade TS. We have a custom power profile on our image so I had to take that into account. Instead of saving the name of the power profile in the TS property PowerPlan, I decided to save the GUID.
    Here is what I am using to get the GUID of the current powerplan:
    ([regex]::Match($((Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power -Filter {isActive='true'} -ErrorAction silentlyContinue).InstanceID).ToString(),"[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12}")).Value

    Reply
  • Pingback: ConfigMgr Task Sequence Collection – GARYTOWN ConfigMgr Blog

Leave a Reply

Your email address will not be published. Required fields are marked *