Skip to main content

How to Change the System's Power Plan in Batch Script

A Windows power plan is a collection of hardware and system settings that manages how your computer uses power. Scripts often need to change the power plan to optimize for a specific task. For example, before running a long, CPU-intensive process like rendering a video or compiling code, you would switch to the "High performance" plan. Conversely, you might switch to "Power saver" on a laptop to conserve battery life during a long copy operation.

This guide will teach you how to use the powerful, built-in powercfg.exe utility to list, view, and change the active power plan from a batch script. You will learn how to identify the correct GUID for each plan and how to create a script that can switch to a specific plan and then restore the original one when it's finished.

The Core Command: powercfg.exe

powercfg.exe is the definitive command-line tool for managing all aspects of power settings in Windows. It can create, delete, modify, and query power schemes (plans).

Crucially, changing the system's power plan often requires elevated privileges. For the most reliable results, you should run your script from a command prompt that has been "Run as Administrator."

Step 1: Listing Available Power Plans

Before you can set a power plan, you need to know which ones are available. The /LIST switch does this.

Command: powercfg /LIST (or powercfg /L)

In the output, this command lists all the power plans on the system. Each plan is identified by a unique GUID and a name. The asterisk (*) indicates the currently active plan.

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)
note

The GUID is the most important piece of information here. It is the unique, permanent identifier for the plan and is the most reliable way to refer to it in a script.

Step 2: Getting the Active Power Plan

To create a script that can restore the original power plan, you first need to capture the current one. The /GETACTIVESCHEME switch is for this.

Command: powercfg /GETACTIVESCHEME

In this output, the command prints the details of the active plan.

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

Step 3: Setting a New Active Power Plan

To change the power plan, you use the /SETACTIVE switch, followed by the GUID of the plan you want to activate.

This script switches the system to the "High performance" plan using its GUID.

@ECHO OFF
REM Run as Administrator.
SET "HighPerfGUID=8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c"

ECHO Switching to High Performance power plan...
powercfg /SETACTIVE %HighPerfGUID%

ECHO Done.

Key powercfg Parameters Explained

  • /LIST or /L: Lists all power plans.
  • /GETACTIVESCHEME: Displays the GUID of the currently active plan.
  • /SETACTIVE <GUID>: Sets the power plan with the specified GUID as active.
  • /QUERY <GUID>: Displays the detailed contents of a power plan.
  • /CHANGE <SETTING> <VALUE>: Modifies a specific setting within the current plan (e.g., powercfg /change monitor-timeout-ac 0 to disable the monitor turning off).

Common Pitfalls and How to Solve Them

  • Not Running as Administrator: Many powercfg operations, especially /SETACTIVE, will fail with an "Access is denied" or similar error if the script is not run from an elevated prompt. Solution: Always run power management scripts as an Administrator.

  • Relying on Plan Names: It's tempting to try to set a plan by name, but powercfg only accepts a GUID for the /SETACTIVE switch. Furthermore, plan names can be changed by the user or localized into different languages. Solution: Always identify the plan you need by its GUID, which is permanent and language-independent.

  • Capturing the GUID: The output of powercfg can be verbose. To get just the GUID into a variable, you need to parse the output with a FOR /F loop. This is shown in the practical example below.

Practical Example: A "High-Performance Task" Wrapper Script

This is the most common use case. The script saves the current power plan, switches to "High performance," runs a long, intensive command, and then restores the original power plan, even if the task fails.

@ECHO OFF
SETLOCAL

REM --- Standard GUIDs for default plans ---
SET "HighPerfGUID=8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c"
SET "OriginalPlanGUID="

ECHO --- High-Performance Task Wrapper ---
ECHO.

REM --- Step 1: Get and save the current active power plan's GUID ---
ECHO Saving the current power plan...
FOR /F "tokens=4" %%G IN ('powercfg /GETACTIVESCHEME') DO (
SET "OriginalPlanGUID=%%G"
)
ECHO Original plan is: %OriginalPlanGUID%

REM --- Step 2: Switch to High Performance ---
ECHO Switching to High Performance mode...
powercfg /SETACTIVE %HighPerfGUID% > NUL

ECHO.
ECHO --- Running the intensive task now. This may take a long time... ---
ECHO.
REM ***************************************************************
REM * YOUR LONG-RUNNING COMMAND GOES HERE *
REM * (e.g., a video render, compile, etc.) *
TIMEOUT /T 10
REM ***************************************************************
ECHO.
ECHO --- Task complete. ---
ECHO.

REM --- Step 3: Restore the original power plan ---
IF DEFINED OriginalPlanGUID (
ECHO Restoring the original power plan...
powercfg /SETACTIVE %OriginalPlanGUID% > NUL
)

ECHO.
ECHO --- Script finished ---
ENDLOCAL

Conclusion

The powercfg.exe utility is the complete and authoritative tool for managing power plans from a batch script.

For reliable power management automation:

  1. Use powercfg /LIST to identify the GUIDs of the available plans.
  2. Use powercfg /GETACTIVESCHEME to find the current plan.
  3. Use powercfg /SETACTIVE <GUID> to change to a new plan.
  4. Always use the GUID, not the name, to refer to a power plan.
  5. Run your scripts as an Administrator to avoid permission errors.

By wrapping your intensive tasks in a script that can manage the power state, you can ensure your processes run with maximum performance and that the system returns to its normal state afterward.