Skip to main content

How to List All Available Power Plans in Batch Script

When building a system configuration tool or an interactive script for end-users, it is often necessary to offer a choice of power plans. Instead of hardcoding standard Windows plans (which might not exist on custom OEM installations or might have been deleted by an administrator), your script should dynamically discover what plans are available on the machine.

In this guide, we will use the Windows powercfg utility within a Batch Script to list all installed power plans, parse their GUIDs and human-readable names, and present them in an interactive menu.

The Raw Powercfg Output

Running powercfg /list (or /l) in the command prompt produces a list of all power schemes installed on the system. The output looks similar to this:

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)

Directly showing this to a user in a Batch Script is acceptable, but it forces them to copy-paste long GUID strings if you want them to select a plan. A better approach is to parse this list and present it cleanly.

Method 1: Simple Power Plan Listing

To extract the names of all available power plans, we use a for /f loop to iterate through the output of powercfg /list, using parentheses as delimiters to isolate the plan name.

@echo off
setlocal enabledelayedexpansion

echo Available Power Plans:
echo ======================

:: Loop through the output of powercfg /list
:: We use parentheses as delimiters: token 1 is everything before "(", token 2 is the name inside "()"
for /f "tokens=1,2 delims=()" %%A in ('powercfg /list') do (
:: Only process lines that contain "Power Scheme GUID:"
echo %%A | find "Power Scheme GUID:" >nul
if !errorlevel! == 0 (
echo Name: %%B
)
)

pause

Understanding the Parsing Logic

  • delims=(): This sets both the open parenthesis ( and close parenthesis ) as separators.
  • tokens=1,2: Token 1 (%%A) captures everything before the (, which includes the prefix text and GUID. Token 2 (%%B) captures the plan name inside the parentheses.
  • The find check filters out the header lines (like "Existing Power Schemes" and the dashes separator) that do not contain Power Scheme GUID:.

Method 2: Extracting Both GUIDs and Names

The most reliable way to separate the GUID from the Name is to use parentheses as the primary delimiter, then use string substitution to strip the prefix text from the GUID portion.

@echo off
setlocal enabledelayedexpansion

echo Scanning for Power Plans...
echo.

set "count=0"

for /f "tokens=1,2 delims=()" %%A in ('powercfg /list') do (
:: Only process lines that contain a Power Scheme GUID
echo %%A | find "Power Scheme GUID:" >nul
if !errorlevel! == 0 (
set /a count+=1

:: The first half (%%A) contains "Power Scheme GUID: [GUID] "
set "raw_guid=%%A"

:: Remove the leading text to isolate the GUID
set "guid=!raw_guid:Power Scheme GUID: =!"

:: Trim trailing spaces
for /f "tokens=1" %%T in ("!guid!") do set "guid=%%T"

:: The second half (%%B) contains the Name
set "name=%%B"

:: Store them in arrays for later use
set "PlanGuid[!count!]=!guid!"
set "PlanName[!count!]=!name!"

:: Display the parsed info
echo [!count!] !name!
echo ID: !guid!
)
)

echo.
echo Found !count! plan(s^).
pause

Example of output:

Available Power Plans:
======================
Name: Kiosk Mode
Name: Balanced
Name: High performance
Name: Power saver

How the GUID Extraction Works

  1. set "guid=!raw_guid:Power Scheme GUID: =!" uses string substitution to remove the Power Scheme GUID: prefix from the raw token, leaving just the GUID followed by trailing spaces.
  2. for /f "tokens=1" %%T in ("!guid!") takes the first space-delimited word from the result, which cleanly isolates the GUID and strips all trailing whitespace.

Method 3: An Interactive Selection Menu

Now that we can list and store the available plans in dynamic variables (PlanGuid[x], PlanName[x]), we can wrap this in a set /p prompt to let the user select and activate a new plan.

@echo off
title Power Plan Selector
setlocal enabledelayedexpansion

:refresh_list
cls
echo =========================================
echo POWER PLAN SELECTOR
echo =========================================
echo.

set "count=0"

:: Get the active plan GUID
set "active_guid="
for /f "tokens=4" %%G in ('powercfg /getactivescheme') do set "active_guid=%%G"

:: List all power plans
for /f "tokens=2,* delims=:" %%A in ('powercfg /list ^| find "Power Scheme GUID"') do (
set /a count+=1

:: Extract GUID (between first { and })
for /f "tokens=1 delims= " %%G in ("%%A") do set "guid=%%G"

:: Extract plan name (remove leading/trailing spaces)
set "name=%%B"
set "name=!name:~1!"

set "PlanGuid[!count!]=!guid!"
set "PlanName[!count!]=!name!"

:: Mark active plan
if "!guid!"=="!active_guid!" (
echo [!count!] !name! (ACTIVE)
) else (
echo [!count!] !name!
)
)

if !count! EQU 0 (
echo [ERROR] No power plans found.
pause
exit /b
)

echo.
echo [0] Exit
echo.

:prompt
set "sel="
set /p "sel=Enter the number to activate (0-!count!): "

:: Handle Exit
if "!sel!"=="0" exit /b

:: Validate input
set /a sel_num=!sel! 2>nul
if "!sel_num!"=="" goto prompt
if !sel_num! lss 1 goto prompt
if !sel_num! gtr !count! goto prompt

:: Get the GUID associated with the chosen number
set "target_guid=!PlanGuid[%sel%]!"
set "target_name=!PlanName[%sel%]!"

if not defined target_guid (
echo [ERROR] Invalid selection.
pause
goto refresh_list
)

echo.
echo Activating "!target_name!"...
powercfg /setactive !target_guid!

if !errorlevel! == 0 (
echo [SUCCESS] Power plan changed.
) else (
echo [ERROR] Failed to change plan.
)

pause
goto refresh_list

Common Mistakes

The Wrong Way: Indexing by Name String

:: WRONG - The user types "High performance"
set /p "name=Enter plan name: "
powercfg /setactive "%name%"

Output Concern: powercfg /setactive must be provided a GUID, not a human-readable string. Passing "High performance" to the command will result in an Invalid Parameters error. You must use the script logic shown in Method 3 to map the chosen number back to the stored GUID array value.

The Wrong Way: Not Using enabledelayedexpansion

:: WRONG - Variables inside a FOR loop won't update
for /f %%A in ('powercfg /list') do (
set count=%count% + 1
echo %count%
)

When building arrays dynamically, you must include setlocal enabledelayedexpansion at the top of the script and utilize exclamation marks (!count!) instead of percent signs (%count%) inside the loop blocks.

Best Practices

  1. Always use GUIDs internally: Hide the GUIDs from the user if you wish, but your script's logic must rely purely on them.
  2. Highlight the active plan: As demonstrated in Method 3, comparing each discovered GUID against the active scheme GUID provides essential context so the user doesn't accidentally re-select the currently active plan.
  3. Validate User Input: Always check if the input number is blank, less than 1, or greater than the total count of discovered plans to prevent your script from attempting to activate a null GUID.

Conclusion

Listing all available power plans in a Batch Script empowers you to build professional-grade configuration utilities that do not rely on hardcoded variables. By parsing the exact output of powercfg /list, filtering out the visual formatting junk, and trapping the data into dynamic arrays, your scripts instantly become highly adaptable to any Windows machine they run on. Integrating this logic into an interactive menu creates an exceptionally robust administrative tool.