badsyntax
badsyntax

Reputation: 311

Changing power plan sub settings with command prompt and powershell doesn't do anything

Im attempting to change power plan settings on a windows 11 machine. I'd like to change what the power button does as well as changing what closing the lid does.

I found this powershell script that I've made edits to.

 # Get Current Active Plan
 $originalPlan = $(powercfg -getactivescheme).split()[3]
 # Duplicate Current Active Plan
 $duplicatedPlan = powercfg -duplicatescheme $originalPlan 

 # Change Name of Duplicated Plan
 powercfg -changename ($duplicatedPlan).split()[3] "Power Plan" "Prevents Sleepy time"
 # Set New Plan as Active Plan
 powercfg -setactive ($duplicatedPlan).split()[3]
 # Get the New Plan

 $newPlan = $(powercfg -getactivescheme).split()[3]
 Write-Output $newPlan
 $GUID = '4f971e89-eebd-4455-a8de-9e59040e7347'
 $powerButtonGUID = '7648efa3-dd9c-4e3e-b566-50f929386280'
 $lidClosedGUID = '5ca83367-6e45-459f-a27b-476b1d01c936'
 $sleepGUID = '96996bc0-ad50-47ec-923b-6f41874dd9eb'


 #POWER BUTTON
 # PowerButton - On Battery - 1 = Sleep
 cmd /c "powercfg /setdcvalueindex $newPlan $GUID $powerButtonGUID 0"
 # PowerButton - While plugged in - 3 = Shutdown
 cmd /c "powercfg /setacvalueindex $newPlan $GUID $powerButtonGUID 0"


 #SLEEP BUTTON
 # On Battery: 
 # 0 = Do Nothing 
 # 1 = Sleep 
 # 2 = Hibernate 
 # 3 = Shut down 
 # 4 = Turn off the display
 cmd /c "powercfg /setdcvalueindex $newPlan $GUID $sleepGUID 0"
 # SleepButton - While plugged in - 0 = Do Nothing
 cmd /c "powercfg /setacvalueindex $newPlan $GUID $sleepGUID 0"


 #LID CLOSED
 # Lid Closed - On Battery - 0 = Do Nothing
 cmd /c "powercfg /setdcvalueindex $newPlan $GUID $lidClosedGUID 0"
 # Lid Closed - While plugged in - 0 = Do Nothing
 cmd /c "powercfg /setacvalueindex $newPlan $GUID $lidClosedGUID 0"
 Write-Output "powercfg /setdcvalueindex $newPlan $GUID $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 15
 #Sleep Mode - While plugged in - 0 = Never
 powercfg -change -standby-timeout-dc 0


 #APPLY CHANGES
 cmd /c "powercfg /s $newPlan"

Creating the new power plan does work as well as the plan settings under # PLAN SETTINGS. However, changing what the lid closed, power button and sleep button does nothing. I get no errors or responses from windows at all. Even if I enter the command manually in the command prompt like so,

powercfg /setdcvalueindex 91f19d7b-04c4-499c-af06-a17bcd74c70c 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0

it completes without error but no settings are changed.

Anyone have insight into this?

Upvotes: 0

Views: 2065

Answers (1)

js2010
js2010

Reputation: 27423

I've done it with the aliases straight from powershell like this:

powercfg /setacvalueindex scheme_current sub_buttons lidaction 0
powercfg /setacvalueindex scheme_current sub_buttons pbuttonaction 3

Upvotes: 0

Related Questions