Partager via


Script a Custom Power Management Policy

Author: Paul Fox, Senior Consultant

Scenario: A customer wants a custom power plan for their laptop images. This is a frequent request to meet new Green initiatives in Federal and State governments.

Here are the steps to incorporate a scripted power configuration. The resulting install.cmd can be embedded into a task sequence of Microsoft Deployment Toolkit.

Note: Powercfg.exe is included in Vista, Windows XP SP2 and Windows Server 2003 operating systems.

1. Configure a power plan through the Control Panel -> Power Options UI

clip_image002[4]

2. Determine the GUID of your new power plan

C:\>Powercfg –l

Existing Power Schemes (* Active)

-----------------------------------

Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) *

Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High performance)

Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Power saver)

3. Export the power plan

C:\ >powercfg -export <plan>.pow <guid_power_plan>

3. Import the <plan.pow> as an Application into MDT server

4. Create an Install.cmd batch file in notepad and call it as a command line parameter when importing into MDT’s Applications, contents as follows:

Note: In this script powercfg.exe will generate the GUID for the imported power plan. You can also assign a GUID to the power plan by passing it with the import command.

powercfg -import filename [GUID]

filename

Specifies a fully qualified path to a file generated by using the powercfg -export option.

GUID

(optional) Represents the settings loaded into a power scheme. If not supplied, Powercfg will generate and use a new GUID

Modify the import and set active portions with:

Set MYGUID=A6319DFD-EEF4-4644-9D74-9724744F1971

Powercfg.exe –import C:\scheme.pow %MYGUID%

Powercfg.exe –setactive %MYGUID%

If you generate your own GUID it is recommended to us a GUID generating utility (e.g. GUIDGEN included in developer tools)

:: Run Power Management Policy

:: Copy files locally, execute then delete

echo

C:

cd \users\public\downloads

mkdir powermgmt

cd powermgmt

copy "\\<MDT_Server>\distribution$\Applications\Laptop Power Management\*.*" \users\public\downloads\powermgmt

:: Import power plan

c:\windows\system32\powercfg -import C:\users\public\downloads\powermgmt\<plan>.pow

:: Get the GUID of the power plan

c:\windows\system32\powercfg -l > plans.txt

findstr /C "<plan_displayname>" plans.txt > import_plan.txt

:: Set power plan to active

for /F "tokens=4 delims= " %%i in (import_plan.txt) do c:\windows\system32\powercfg -setactive %%i

:: Delete

cd ..

rd /Q /S powermgmt

5. Open Control Panel -> Power Options UI and you will see you custom plan as “active.”

clip_image004[4]

More information about Powercfg.exe can be found at https://technet2.microsoft.com/WindowsVista/en/library/1d58b934-f56a-4796-b2df-7be2eb9c03bc1033.mspx?mfr=true

Comments

  • Anonymous
    January 01, 2003
    There is a tonne of information available on Vista power management, from whitepapers to videos to blog

  • Anonymous
    February 07, 2011
    is there a way to import power settings into a scheme that already exists? everytime i try to do it it was the specified GUID already exists?

  • Anonymous
    September 15, 2011
    Does this same procedure work with Windows XP  w/SP3  x86 and Windows 2003 R2 w/SP2 x86 and x64? I will try it and post the results.

  • Anonymous
    May 31, 2012
    What about Server 2003 under the "Advanced" Tab?  For example, "When I close the lid of my portable computer:" -- I want to set it to "Do nothing" but I've not yet found a solution. Any help you could provide would be great! Thanks!

  • Anonymous
    March 11, 2014
    Thank you for the nice script but I can't get it working in a batch file. I put below input & creates the power plan but doesn't get it activated

    cd userspublicdownloads

    mkdir powermgmt

    cd powermgmt

    copy "c:custompowerplan.pow" userspublicdownloadspowermgmt

    powercfg -import "c:userspublicdownloadspowermgmtcustompowerplan.pow"

    c:windowssystem32powercfg -l > plans.txt

    findstr /C "" plans.txt > import_plan.txt

    timeout /t 5

    for /F "tokens=4 delims= " %i in (import_plan.txt) do c:windowssystem32powercfg -setactive %i

    timeout /t 5

    cd ..

    rd /Q /S C:UsersPublicDownloadspowermgmt

  • Anonymous
    March 11, 2014
    Kindly help. It's urgent & we really need this to be working in a batch file. [Aaron Margosis]  See pfox's comment below.

  • Anonymous
    March 11, 2014
    Did you enter the name of your power plan in the FindStr command?
    findstr /C "" plans.txt > import_plan.txt

    for example if you want to set the “Balanced” plan it should read

    findstr /C "Balanced" plans.txt > import_plan.txt