Skip to main content

How to Delete a Power Plan in Batch Script

Over time, computers can accumulate a clutter of duplicate or obsolete power plans, especially if automated scripts unreliably duplicate existing schemes instead of updating them. Deleting these redundant plans is crucial for maintaining a clean and understandable system configuration for both the administrator and the end-user.

In this guide, we will use the powercfg /delete command within a Batch Script to locate and securely remove a specific custom power plan by name, while avoiding critical errors like attempting to delete the currently active plan.

The Challenge of Deleting a Power Plan

The primary hurdle in deleting a power plan is that powercfg /delete only accepts a GUID (the internal alphanumeric identifier), not the plan's human-readable name (like "My Kiosk Plan").

Furthermore, Windows enforces a strict rule: You cannot delete the power plan that is currently active. If your script tries to delete the active plan, powercfg will throw an error and fail. Therefore, our script must be intelligent enough to:

  1. Find the GUID associated with the custom name.
  2. Check if that GUID is the active plan.
  3. Switch off the active plan if necessary.
  4. Delete the GUID.

The Script: Finding and Deleting a Plan by Name

Let's assume our automated deployments accidentally created a clutter of plans named "Temporary Build Profile". We need to find its GUID and safely terminate it.

The output of powercfg /list produces lines like:

Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) *
Power Scheme GUID: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee (Temporary Build Profile)

Each line contains the GUID after the colon and the friendly name inside parentheses. The active plan is marked with a trailing *. Our script parses these lines using the parentheses as delimiters to separate the GUID portion from the name.

@echo off
setlocal enabledelayedexpansion

:: Define the name of the power plan to delete
set "target_name=Temporary Build Profile"

echo Searching for "%target_name%"...
set "target_guid="

:: 1. Search the power scheme list safely
for /f "tokens=*" %%L in ('powercfg /list') do (
set "line=%%L"

echo !line! | find "Power Scheme GUID:" >nul
if !errorlevel! equ 0 (
:: Extract GUID
set "guid=!line:*Power Scheme GUID: =!"
for /f "tokens=1" %%T in ("!guid!") do set "guid=%%T"

:: Extract Name (text inside parentheses)
for /f "tokens=2 delims=()" %%N in ("!line!") do set "name=%%N"

:: Compare with target name
if /i "!name!"=="%target_name%" (
set "target_guid=!guid!"
goto :plan_found
)
)
)

:plan_not_found
echo [INFO] Plan "%target_name%" does not exist.
pause
exit /b 0

:plan_found
echo.
echo Found target plan: !target_guid!

:: 2. Check if the target plan is currently active
set "active_guid="
for /f "tokens=*" %%L in ('powercfg /getactivescheme') do (
set "active_line=%%L"
set "active_guid=!active_line:*Power Scheme GUID: =!"
for /f "tokens=1" %%T in ("!active_guid!") do set "active_guid=%%T"
)

if /i "!active_guid!"=="!target_guid!" (
echo [WARNING] The target plan is currently active.
echo Switching to the standard "Balanced" plan before deletion...

:: Balanced power plan GUID (universal)
powercfg /setactive 381b4222-f694-41f0-9685-ff5bb260df2e

if !errorlevel! neq 0 (
echo [ERROR] Failed to switch plans. Deletion aborted.
pause
exit /b 1
)
echo [OK] Successfully switched to Balanced.
)

:: 3. Delete the plan
echo Deleting custom plan !target_guid!...
powercfg /delete !target_guid!

if !errorlevel! equ 0 (
echo [SUCCESS] "%target_name%" has been deleted.
) else (
echo [ERROR] Failed to delete power plan. Check permissions or if it's protected.
)

pause

Explaining the Safety Logic

  • Finding the GUID: The for /f loop splits each line of powercfg /list output on the parentheses characters. The text before the ( contains the GUID label, and the text between ( and ) contains the friendly name. We strip the Power Scheme GUID: prefix and isolate the first token to get a clean GUID.
  • The Active Check: We parse the output of powercfg /getactivescheme using the same GUID-extraction technique. If the active GUID matches our target, the script switches the machine to the universally known Balanced plan before executing the /delete command. This prevents the script from crashing.

Deleting All Copies of a Duplicated Plan

If a poorly written script mistakenly ran 10 times, you might have 10 separate power plans all named "Temporary Build Profile". The script above only deletes the first one it finds (because of the goto :plan_found).

To clean up a disastrous proliferation of duplicate plans, we remove the goto and allow the loop to find and delete every matching instance.

@echo off
setlocal enabledelayedexpansion

set "target_name=Temporary Build Profile"
set "deleted_count=0"

echo Scanning system for redundant "%target_name%" plans...
echo.

:: Get the active plan GUID upfront
set "active_guid="
for /f "tokens=*" %%L in ('powercfg /getactivescheme') do (
set "active_line=%%L"
set "active_guid=!active_line:*Power Scheme GUID: =!"
for /f "tokens=1" %%T in ("!active_guid!") do set "active_guid=%%T"
)

:: Loop through all installed plans
for /f "tokens=1,2 delims=()" %%A in ('powercfg /list') do (
echo %%A | find "Power Scheme GUID:" >nul
if !errorlevel! equ 0 (
set "raw_line=%%A"
set "guid=!raw_line:*Power Scheme GUID: =!"
for /f "tokens=1" %%T in ("!guid!") do set "guid=%%T"
set "name=%%B"

if /i "!name!"=="%target_name%" (
echo Found: !guid!

if /i "!guid!"=="!active_guid!" (
echo - Plan is active. Switching to "Balanced"...
powercfg /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
:: Update the active GUID so we don't try to switch again
set "active_guid=381b4222-f694-41f0-9685-ff5bb260df2e"
)

powercfg /delete !guid!

if !errorlevel! equ 0 (
echo - [DELETED]
set /a deleted_count+=1
) else (
echo - [ERROR] Could not delete.
)
)
)
)

echo.
echo Cleanup finished. Deleted !deleted_count! plan(s^) named "%target_name%".
pause

This bulk-deletion strategy is a common administrative cleanup tool for lab environments.

Common Mistakes

The Wrong Way: Deleting Default Windows Plans

:: WRONG - The system protects built-in schemes
powercfg /delete 381b4222-f694-41f0-9685-ff5bb260df2e

Output Concern: You cannot delete the core Microsoft power plans (Balanced, Saver, Performance). Only custom, duplicated plans created by users or OEMs can be deleted via /delete. Attempting to delete a default plan returns an Invalid Parameters or Access Denied error.

The Wrong Way: Using the Name Parameter

:: WRONG - /delete requires a GUID
powercfg /delete "My Custom Plan"

The command will fail instantly because /delete requires the alphanumeric GUID string parsed from the list, not the friendly name.

Best Practices

  1. Never assume the plan isn't active: A power plan cannot be deleted if the OS is currently running on it. Always retrieve the active GUID first and verify it against your target.
  2. Fallback securely: When shifting off a target active plan, always revert to the "Balanced" default ID (381b...). It exists natively on 100% of Windows installations.
  3. Use exact name matches: Ensure your if /i "!name!"=="%target_name%" condition demands an exact (though case-insensitive) match so you don't inadvertently delete "Kiosk Render Mode" when searching for "Kiosk Mode".

Conclusion

Deleting an obsolete or duplicated power plan via Batch Script requires navigating the strict requirements of the powercfg utility. By parsing the list of schemes to map human-readable names to their specific internal GUIDs, and incorporating robust safety checks to ensure the target plan is not currently active, administrators can confidently deploy cleanup scripts to maintain a pristine, understandable power configuration across their fleets.