Skip to content

Instantly share code, notes, and snippets.

@nbrew
Created May 23, 2014 00:49
Show Gist options
  • Save nbrew/a8df78afdf24ed7e423d to your computer and use it in GitHub Desktop.
Save nbrew/a8df78afdf24ed7e423d to your computer and use it in GitHub Desktop.
Batch file to toggle between two POWERCFG schemes.
@ECHO OFF
'
' SETUP:
' To get the GUIDs required, in Windows Powershell, run:
'
' POWERCFG -L
'
' Then select and right-click a GUID to copy.
'
' To run this script when the machine wakes from sleep:
' 1. Create a new task in Task Scheduler.
' 2. New Trigger -> Begin the task: On an Event
' Log: SYSTEM
' Source: Power-Troubleshooter
' Event ID: 1
' 3. Run Program -> Browse to this script.
'
' Additionally, you can schedule this script to run at midnight to switch profiles (and ideally go to sleep).
'
SET performanceGuid=''
SET sleepGuid=''
for /f "tokens=2 delims=:(" %%x in ('powercfg -getactivescheme') do SET currentGuid=%%x
set currentGuid=%currentGuid: =%
IF "%currentGuid%" == "%performanceGuid%" (
POWERCFG -SETACTIVE "%sleepGuid%"
) ELSE (
POWERCFG -SETACTIVE "%performanceGuid%"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment