SOLVED

Creating Powerplans

%3CLINGO-SUB%20id%3D%22lingo-sub-1643119%22%20slang%3D%22en-US%22%3ECreating%20Powerplans%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1643119%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20create%20a%20script%20using%20Powershell%20to%20set%20a%20default%20power%20plan.%3C%2FP%3E%3CP%3EI%20already%20found%20something%20for%20the%20good%20old%20CMD%20but%20nothing%20yet%20for%20Powershell%2C%20so%20maybe%20you%20guys%20can%20help%3F!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20Settings%3A%3C%2FP%3E%3CUL%3E%3CLI%3EPowerbutton%3A%3CUL%3E%3CLI%3EWhen%20I%20press%20Powerbutton%3A%20Shutdown%20-%20Shutdown%3C%2FLI%3E%3CLI%3EWhen%20I%20press%20Sleepbutton%3A%20Nothing%20-%20Nothing%3C%2FLI%3E%3CLI%3EWhen%20i%20close%20the%20lid%3A%20-Nothing%20-nothing%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3EPlan-Settings%3A%3CUL%3E%3CLI%3ETurn%20off%20Display%3A%2015min%20-%20never%3C%2FLI%3E%3CLI%3EPut%20it%20to%20sleep%3A%20Never%20-%20Never%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20appreciate%20if%20you%20could%20give%20me%20some%20advice%20on%20how%20to%20use%20Powershell%20creating%20%22Power-Plans%22.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EGreetings%26nbsp%3B%3C%2FP%3E%3CP%3EYannik%26nbsp%3BSchulz%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1643119%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPower%20shell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1647643%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20Powerplans%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1647643%22%20slang%3D%22en-US%22%3E%3CP%3E%3CBR%20%2F%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F784168%22%20target%3D%22_blank%22%3E%40Schulzi%3C%2FA%3E%2C%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EThis%20is%20the%20PowerShell%20Script%20which%20is%20set%20the%20default%20(Active)%20power%20plan%20as%20you%20wish.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24CurrentPlan%20%3D%20%24(powercfg%20-getactivescheme).split()%5B3%5D%0A%0A%24PowerGUID%20%3D%20'4f971e89-eebd-4455-a8de-9e59040e7347'%0A%24PowerButtonGUID%20%3D%20'7648efa3-dd9c-4e3e-b566-50f929386280'%0A%24LidClosedGUID%20%3D%20'5ca83367-6e45-459f-a27b-476b1d01c936'%0A%24SleepGUID%20%3D%20'238c9fa8-0aad-41ed-83f4-97be242c8f20'%0A%0A%0A%23POWER%20BUTTON%0A%0A%23%20PowerButton%20-%20On%20Battery%20-%201%20%3D%20Sleep%0Acmd%20%2Fc%20%22powercfg%20%2Fsetdcvalueindex%20%24CurrentPlan%20%24PowerGUID%20%24PowerButtonGUID%203%22%0A%23%20PowerButton%20-%20While%20plugged%20in%20-%203%20%3D%20Shutdown%0Acmd%20%2Fc%20%22powercfg%20%2Fsetacvalueindex%20%24CurrentPlan%20%24PowerGUID%20%24PowerButtonGUID%203%22%0A%0A%0A%23SLEEP%20BUTTON%0A%0A%23%20SleepButton%20-%20On%20Battery%20-%200%20%3D%20Do%20Nothing%0Acmd%20%2Fc%20%22powercfg%20%2Fsetdcvalueindex%20%24CurrentPlan%20%24PowerGUID%20%24SleepGUID%200%22%0A%23%20SleepButton%20-%20While%20plugged%20in%20-%200%20%3D%20Do%20Nothing%0Acmd%20%2Fc%20%22powercfg%20%2Fsetacvalueindex%20%24CurrentPlan%20%24PowerGUID%20%24SleepGUID%200%22%0A%0A%0A%23LID%20CLOSED%0A%0A%23%20Lid%20Closed%20-%20On%20Battery%20-%200%20%3D%20Do%20Nothing%0Acmd%20%2Fc%20%22powercfg%20%2Fsetdcvalueindex%20%24CurrentPlan%20%24PowerGUID%20%24LidClosedGUID%200%22%0A%23%20Lid%20Closed%20-%20While%20plugged%20in%20-%200%20%3D%20Do%20Nothing%0Acmd%20%2Fc%20%22powercfg%20%2Fsetacvalueindex%20%24CurrentPlan%20%24PowerGUID%20%24LidClosedGUID%200%22%0A%0A%0A%23%20PLAN%20SETTINGS%0A%0A%23Turn%20off%20Display%20-%20On%20Battery%20-%2015%20%3D%2015%20Minutes%0Apowercfg%20-change%20-monitor-timeout-dc%2015%0A%23Turn%20off%20Display%20-%20While%20plugged%20in%20-%200%20%3D%20Never%0Apowercfg%20-change%20-monitor-timeout-ac%200%0A%23Sleep%20Mode%20-%20On%20Battery%20-%200%20%3D%20Never%0Apowercfg%20-change%20-standby-timeout-ac%200%0A%23Sleep%20Mode%20-%20While%20plugged%20in%20-%200%20%3D%20Never%0Apowercfg%20-change%20-standby-timeout-dc%200%0A%0A%0A%23APPLY%0Acmd%20%2Fc%20%22powercfg%20%2Fs%20%24CurrentPlan%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20want%20to%20make%20changes%20to%20power%20plan%20settings%20you%20can%20learn%20the%20GUIDs%20and%20action%20values%20from%20the%20link%20below%3A%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows-hardware%2Fcustomize%2Fpower-settings%2Fconfigure-power-settings%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows-hardware%2Fcustomize%2Fpower-settings%2Fconfigure-power-settings%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EHave%20a%20nice%20day.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1648820%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20Powerplans%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1648820%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F784168%22%20target%3D%22_blank%22%3E%40Schulzi%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20powershell%20script%20creates%20a%20new%20power%20plan%20and%20set%20it%20as%20you%20wish.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%23%20Get%20Current%20Active%20Plan%0A%24OriginalPlan%20%3D%20%24(powercfg%20-getactivescheme).split()%5B3%5D%0A%23%20Duplicate%20Current%20Active%20Plan%0A%24Duplicate%20%3D%20powercfg%20-duplicatescheme%20%24OriginalPlan%0A%23%20Change%20Name%20of%20Duplicated%20Plan%0A%24CurrentPlan%20%3D%20powercfg%20-changename%20(%24Duplicate).split()%5B3%5D%20%22Custom%20Plan%203%22%0A%23%20Set%20New%20Plan%20as%20Active%20Plan%0A%24SetActiveNewPlan%20%3D%20powercfg%20-setactive%20(%24Duplicate).split()%5B3%5D%0A%23%20Get%20the%20New%20Plan%0A%24NewPlan%20%3D%20%24(powercfg%20-getactivescheme).split()%5B3%5D%0A%0A%24PowerGUID%20%3D%20'4f971e89-eebd-4455-a8de-9e59040e7347'%0A%24PowerButtonGUID%20%3D%20'7648efa3-dd9c-4e3e-b566-50f929386280'%0A%24LidClosedGUID%20%3D%20'5ca83367-6e45-459f-a27b-476b1d01c936'%0A%24SleepGUID%20%3D%20'238c9fa8-0aad-41ed-83f4-97be242c8f20'%0A%0A%0A%23POWER%20BUTTON%0A%0A%23%20PowerButton%20-%20On%20Battery%20-%201%20%3D%20Sleep%0Acmd%20%2Fc%20%22powercfg%20%2Fsetdcvalueindex%20%24NewPlan%20%24PowerGUID%20%24PowerButtonGUID%203%22%0A%23%20PowerButton%20-%20While%20plugged%20in%20-%203%20%3D%20Shutdown%0Acmd%20%2Fc%20%22powercfg%20%2Fsetacvalueindex%20%24NewPlan%20%24PowerGUID%20%24PowerButtonGUID%203%22%0A%0A%0A%23SLEEP%20BUTTON%0A%0A%23%20SleepButton%20-%20On%20Battery%20-%200%20%3D%20Do%20Nothing%0Acmd%20%2Fc%20%22powercfg%20%2Fsetdcvalueindex%20%24NewPlan%20%24PowerGUID%20%24SleepGUID%200%22%0A%23%20SleepButton%20-%20While%20plugged%20in%20-%200%20%3D%20Do%20Nothing%0Acmd%20%2Fc%20%22powercfg%20%2Fsetacvalueindex%20%24NewPlan%20%24PowerGUID%20%24SleepGUID%200%22%0A%0A%0A%23LID%20CLOSED%0A%0A%23%20Lid%20Closed%20-%20On%20Battery%20-%200%20%3D%20Do%20Nothing%0Acmd%20%2Fc%20%22powercfg%20%2Fsetdcvalueindex%20%24NewPlan%20%24PowerGUID%20%24LidClosedGUID%200%22%0A%23%20Lid%20Closed%20-%20While%20plugged%20in%20-%200%20%3D%20Do%20Nothing%0Acmd%20%2Fc%20%22powercfg%20%2Fsetacvalueindex%20%24NewPlan%20%24PowerGUID%20%24LidClosedGUID%200%22%0A%0A%0A%23%20PLAN%20SETTINGS%0A%0A%23Turn%20off%20Display%20-%20On%20Battery%20-%2015%20%3D%2015%20Minutes%0Apowercfg%20-change%20-monitor-timeout-dc%2015%0A%23Turn%20off%20Display%20-%20While%20plugged%20in%20-%200%20%3D%20Never%0Apowercfg%20-change%20-monitor-timeout-ac%200%0A%23Sleep%20Mode%20-%20On%20Battery%20-%200%20%3D%20Never%0Apowercfg%20-change%20-standby-timeout-ac%200%0A%23Sleep%20Mode%20-%20While%20plugged%20in%20-%200%20%3D%20Never%0Apowercfg%20-change%20-standby-timeout-dc%200%0A%0A%0A%23APPLY%20CHANGES%0Acmd%20%2Fc%20%22powercfg%20%2Fs%20%24NewPlan%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20want%20to%20add%20or%20change%20properties%20of%20this%20power%20plan%20you%20can%20check%20the%20link%20below%20which%20has%20GUIDs%20and%20actions%20about%20power%20plans.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows-hardware%2Fcustomize%2Fpower-settings%2Fconfigure-power-settings%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows-hardware%2Fcustomize%2Fpower-settings%2Fconfigure-power-settings%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20a%20nice%20day%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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

5 Replies
Highlighted


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.

 

Highlighted
Best Response confirmed by Schulzi (Occasional Contributor)
Solution

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-settings

 

Have a nice day

 

 

Highlighted
Hi @hasanemresatilmis,

Thanks for your reply, really helped me here.
Now I know what I have to do for the next time.

Greetings
Yannik
Highlighted
Hi @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
Highlighted

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Ş