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/

9 thoughts on “Change and Restore Power Plan during TS”

  1. 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
  2. Hi,
    i like your article and it´s looks like good.
    I´ve implemented it yet into a OSD but in the WINPE section the settings will fail so set it up after the WINPE section for OS install and this will work now but it looks like so that the setting is history after a new restart session.

    Actually i can´t check because my WINPE don´t work with F8 to controll it so i will repeat it with another one.

    In the WINPE Section i work with another setting and looks like so.
    %SYSTEMROOT%\system32\powercfg -s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
    This works fine in WINPE as oneline script.

    Reply
    • This post was intended for when you run a TS for Upgrades or software installs, not for during WinPE (as you found out). If you’re running in PE, there is no need to grab the current settings and save for later, you can just simply set the power scheme that you desire, which looks like you’ve figured out.

      Reply
    • You can use this for offline TS.
      The WMI provider is not fully loaded and it’s missing some libraries when using the boot image.

      PowerShell.exe -ExecutionPolicy Bypass -Command “& {$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value(‘PowerPlan’) = (PowerCfg.exe /GETACTIVESCHEME | Select-String -Pattern ‘(?<=\()(.*?)(?=\))' | Select-Object -ExpandProperty Matches).Value"

      Reply
  3. You used the same GUID for Balanced and Power Saver. The proper command line for Balanced is
    PowerCfg.exe /s 381b4222-f694-41f0-9685-ff5bb260df2e

    Reply
  4. As far as machines with modern standby, they don’t have anything but a balanced power profile. Is disabling that via the csenabled registry key what other folks do or would you create a custom power profile to use during these steps?

    Reply
    • Since CM has added the option to check a box to run the TS in high performance mode, this post has probably become obsolete. We have stopped using high performance mode during our task sequences as we found on some models, and rare situations, it would cause the machines to overheat and shutdown.

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.