Forum Discussion
Creating Powerplans
Hello,
I want to create a script using Powershell to set a default power plan.
I already found something for the good old CMD but nothing yet for Powershell, so maybe you guys can help?!
The Settings:
- Powerbutton:
- When I press Powerbutton: Shutdown - Shutdown
- When I press Sleepbutton: Nothing - Nothing
- When i close the lid: -Nothing -nothing
- Plan-Settings:
- Turn off Display: 15min - never
- Put it to sleep: Never - Never
I would appreciate if you could give me some advice on how to use Powershell creating "Power-Plans".
Greetings
Yannik Schulz
Hi Schulzi,
This powershell script creates a new power plan and set it as you wish.
# Get Current Active Plan $OriginalPlan = $(powercfg -getactivescheme).split()[3] # Duplicate Current Active Plan $Duplicate = powercfg -duplicatescheme $OriginalPlan # Change Name of Duplicated Plan $CurrentPlan = powercfg -changename ($Duplicate).split()[3] "Custom Plan 3" # Set New Plan as Active Plan $SetActiveNewPlan = powercfg -setactive ($Duplicate).split()[3] # Get the New Plan $NewPlan = $(powercfg -getactivescheme).split()[3] $PowerGUID = '4f971e89-eebd-4455-a8de-9e59040e7347' $PowerButtonGUID = '7648efa3-dd9c-4e3e-b566-50f929386280' $LidClosedGUID = '5ca83367-6e45-459f-a27b-476b1d01c936' $SleepGUID = '238c9fa8-0aad-41ed-83f4-97be242c8f20' #POWER BUTTON # PowerButton - On Battery - 1 = Sleep cmd /c "powercfg /setdcvalueindex $NewPlan $PowerGUID $PowerButtonGUID 3" # PowerButton - While plugged in - 3 = Shutdown cmd /c "powercfg /setacvalueindex $NewPlan $PowerGUID $PowerButtonGUID 3" #SLEEP BUTTON # SleepButton - On Battery - 0 = Do Nothing cmd /c "powercfg /setdcvalueindex $NewPlan $PowerGUID $SleepGUID 0" # SleepButton - While plugged in - 0 = Do Nothing cmd /c "powercfg /setacvalueindex $NewPlan $PowerGUID $SleepGUID 0" #LID CLOSED # Lid Closed - On Battery - 0 = Do Nothing cmd /c "powercfg /setdcvalueindex $NewPlan $PowerGUID $LidClosedGUID 0" # Lid Closed - While plugged in - 0 = Do Nothing cmd /c "powercfg /setacvalueindex $NewPlan $PowerGUID $LidClosedGUID 0" # PLAN SETTINGS #Turn off Display - On Battery - 15 = 15 Minutes powercfg -change -monitor-timeout-dc 15 #Turn off Display - While plugged in - 0 = Never powercfg -change -monitor-timeout-ac 0 #Sleep Mode - On Battery - 0 = Never powercfg -change -standby-timeout-ac 0 #Sleep Mode - While plugged in - 0 = Never powercfg -change -standby-timeout-dc 0 #APPLY CHANGES cmd /c "powercfg /s $NewPlan"
If you want to add or change properties of this power plan you can check the link below which has GUIDs and actions about power plans.
https://docs.microsoft.com/en-us/windows-hardware/customize/power-settings/configure-power-settingsHave a nice day
- hasanemresatilmisIron Contributor
Hi Schulzi,This is the PowerShell Script which is create and set the new power plan as you wish.
# Get Current Active Plan $OriginalPlan = $(powercfg -getactivescheme).split()[3] # Duplicate Current Active Plan $Duplicate = powercfg -duplicatescheme $OriginalPlan # Change Name of Duplicated Plan $CurrentPlan = powercfg -changename ($Duplicate).split()[3] "Custom Plan 3" # Set New Plan as Active Plan $SetActiveNewPlan = powercfg -setactive ($Duplicate).split()[3] # Get the New Plan $NewPlan = $(powercfg -getactivescheme).split()[3] $PowerGUID = '4f971e89-eebd-4455-a8de-9e59040e7347' $PowerButtonGUID = '7648efa3-dd9c-4e3e-b566-50f929386280' $LidClosedGUID = '5ca83367-6e45-459f-a27b-476b1d01c936' $SleepGUID = '238c9fa8-0aad-41ed-83f4-97be242c8f20' #POWER BUTTON # PowerButton - On Battery - 1 = Sleep cmd /c "powercfg /setdcvalueindex $NewPlan $PowerGUID $PowerButtonGUID 3" # PowerButton - While plugged in - 3 = Shutdown cmd /c "powercfg /setacvalueindex $NewPlan $PowerGUID $PowerButtonGUID 3" #SLEEP BUTTON # SleepButton - On Battery - 0 = Do Nothing cmd /c "powercfg /setdcvalueindex $NewPlan $PowerGUID $SleepGUID 0" # SleepButton - While plugged in - 0 = Do Nothing cmd /c "powercfg /setacvalueindex $NewPlan $PowerGUID $SleepGUID 0" #LID CLOSED # Lid Closed - On Battery - 0 = Do Nothing cmd /c "powercfg /setdcvalueindex $NewPlan $PowerGUID $LidClosedGUID 0" # Lid Closed - While plugged in - 0 = Do Nothing cmd /c "powercfg /setacvalueindex $NewPlan $PowerGUID $LidClosedGUID 0" # PLAN SETTINGS #Turn off Display - On Battery - 15 = 15 Minutes powercfg -change -monitor-timeout-dc 15 #Turn off Display - While plugged in - 0 = Never powercfg -change -monitor-timeout-ac 0 #Sleep Mode - On Battery - 0 = Never powercfg -change -standby-timeout-ac 0 #Sleep Mode - While plugged in - 0 = Never powercfg -change -standby-timeout-dc 0 #APPLY cmd /c "powercfg /s $NewPlan"
If you want to make changes to power plan settings you can learn the GUIDs and action values from the link below:
https://docs.microsoft.com/en-us/windows-hardware/customize/power-settings/configure-power-settings
Have a nice day.- kmzaragozabCopper ContributorHi! Just a question ¿What does the split at the first line? Cause when i try to run it, it appears an error.
- hasanemresatilmisIron Contributor
- hasanemresatilmisIron Contributor
Hi Schulzi,
This powershell script creates a new power plan and set it as you wish.
# Get Current Active Plan $OriginalPlan = $(powercfg -getactivescheme).split()[3] # Duplicate Current Active Plan $Duplicate = powercfg -duplicatescheme $OriginalPlan # Change Name of Duplicated Plan $CurrentPlan = powercfg -changename ($Duplicate).split()[3] "Custom Plan 3" # Set New Plan as Active Plan $SetActiveNewPlan = powercfg -setactive ($Duplicate).split()[3] # Get the New Plan $NewPlan = $(powercfg -getactivescheme).split()[3] $PowerGUID = '4f971e89-eebd-4455-a8de-9e59040e7347' $PowerButtonGUID = '7648efa3-dd9c-4e3e-b566-50f929386280' $LidClosedGUID = '5ca83367-6e45-459f-a27b-476b1d01c936' $SleepGUID = '238c9fa8-0aad-41ed-83f4-97be242c8f20' #POWER BUTTON # PowerButton - On Battery - 1 = Sleep cmd /c "powercfg /setdcvalueindex $NewPlan $PowerGUID $PowerButtonGUID 3" # PowerButton - While plugged in - 3 = Shutdown cmd /c "powercfg /setacvalueindex $NewPlan $PowerGUID $PowerButtonGUID 3" #SLEEP BUTTON # SleepButton - On Battery - 0 = Do Nothing cmd /c "powercfg /setdcvalueindex $NewPlan $PowerGUID $SleepGUID 0" # SleepButton - While plugged in - 0 = Do Nothing cmd /c "powercfg /setacvalueindex $NewPlan $PowerGUID $SleepGUID 0" #LID CLOSED # Lid Closed - On Battery - 0 = Do Nothing cmd /c "powercfg /setdcvalueindex $NewPlan $PowerGUID $LidClosedGUID 0" # Lid Closed - While plugged in - 0 = Do Nothing cmd /c "powercfg /setacvalueindex $NewPlan $PowerGUID $LidClosedGUID 0" # PLAN SETTINGS #Turn off Display - On Battery - 15 = 15 Minutes powercfg -change -monitor-timeout-dc 15 #Turn off Display - While plugged in - 0 = Never powercfg -change -monitor-timeout-ac 0 #Sleep Mode - On Battery - 0 = Never powercfg -change -standby-timeout-ac 0 #Sleep Mode - While plugged in - 0 = Never powercfg -change -standby-timeout-dc 0 #APPLY CHANGES cmd /c "powercfg /s $NewPlan"
If you want to add or change properties of this power plan you can check the link below which has GUIDs and actions about power plans.
https://docs.microsoft.com/en-us/windows-hardware/customize/power-settings/configure-power-settingsHave a nice day
- SchulziBrass ContributorHi hasanemresatilmis,
Thanks for your reply, really helped me here.
Now I know what I have to do for the next time.
Greetings
Yannik - SchulziBrass ContributorHi hasanemresatilmis,
I just noticed a minor flaw in your script.
$SleepGUID = "238c9fa8-0aad-41ed-83f4-97be242c8f20" isn't right anymore.
Instead use $SleepGUID = "96996bc0-ad50-47ec-923b-6f41874dd9eb"
Now it should work without Problems.
Greetings
Yannik- hasanemresatilmisIron Contributor
Hi Schulzi ,
You're right. Thanks for the information.
This is the link which I took SleepGUID for Sleep Settings
https://docs.microsoft.com/en-us/windows-hardware/customize/power-settings/sleep-settings
This is the link which is correct SleepGUID for Sleep Button
https://docs.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-sleep-button-action
Greetings
Hasan Emre SATILMIŞ