Duplicating and editing power settings using powercfg

2.1k Views Asked by At

I would like to use the powercfg tool in Windows to duplicate my current power scheme and then change the new scheme (enabling me to revert back to the old scheme if I mess something up) using a batch file.

I know that powercfg -getactivescheme would return the current scheme's GUID

powercfg -setactive [GUID] would set a GUID to the current scheme, but how would I know what GUID to use? That is, how would I know what the duplicated scheme's new GUID would be?

1

There are 1 best solutions below

0
On

Executing powercfg -l on my machine returns the following:

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)

Then when you duplicate the current active scheme with powercfg -duplicatescheme 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c the output is as follows:

Power Scheme GUID: d0b7e1f3-c9ed-49d1-93d4-6ed688244dea  (High performance)

Seems to me that capturing tokens=4 from the powercfg -duplicatescheme command would get you your backup scheme's GUID.

@echo off
setlocal
rem get current scheme
for /f "tokens=4" %%I in ('powercfg -getactivescheme') do set current=%%I

rem create backup
for /f "tokens=4" %%I in ('powercfg -duplicatescheme %current%') do set backup=%%I

rem switch to backup
powercfg -setactive %backup%
echo Switched from %current% to %backup%