Powershell Set Lid Close Action Powershell Set Lid Close Action powershell powershell

Powershell Set Lid Close Action


I wanted to do the same thing et get the exact same problem. Finally, I found that you need to insert in your command line the registry keys that are superior to the one you want to modify:

powercfg -setacvalueindex 5ca83367-6e45-459f-a27b-476b1d01c936 0powercfg -setdcvalueindex 5ca83367-6e45-459f-a27b-476b1d01c936 0

should become:

powercfg -setacvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0powercfg -setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0

Just put that in a BAT file and you're ready to go!


Try the WMI accelerator:

$class = ([wmi] '\root\cimv2\power:Win32_PowerSettingDataIndex.InstanceID="Microsoft:PowerSettingDataIndex\\{8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c}\\DC\\{5ca83367-6e45-459f-a27b-476b1d01c936}"')$class.SettingIndexValue = 0$class.Put()


Honestly, I don't see any reason why you shouldn't use tools that simply work... ;)Anyways: when working with WMI is usually good idea to filter as much to the left as you can. Should not make much difference here, but at times difference is huge. This is how I would do it with WMI:

$Name = @{    Namespace = 'root\cimv2\power'}$ID = (Get-WmiObject @Name Win32_PowerPlan -Filter "IsActive = TRUE") -replace '.*(\{.*})"', '$1'$Lid = '{5ca83367-6e45-459f-a27b-476b1d01c936}'Get-WmiObject @Name Win32_PowerSettingDataIndex -Filter "InstanceId LIKE '%$Id\\%C\\$Lid'" |     Set-WmiInstance -Arguments @{ SettingIndexValue = 0 }

There may be better way with more advanced WQL query, this is almost the same what you did, only bit modified.