Sep 07 2020 11:16 PM
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:
I would appreciate if you could give me some advice on how to use Powershell creating "Power-Plans".
Greetings
Yannik Schulz
Sep 09 2020 03:51 AM - edited Sep 09 2020 04:52 AM
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.
Sep 09 2020 07:28 AM
SolutionHi @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-settings
Have a nice day
Sep 09 2020 11:07 PM
Sep 09 2020 11:38 PM
Sep 09 2020 11:55 PM
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-sett...
Greetings
Hasan Emre SATILMIŞ
Mar 28 2022 08:57 AM
Apr 12 2022 12:31 AM
Sep 09 2020 07:28 AM
SolutionHi @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-settings
Have a nice day