Skip to content

Instantly share code, notes, and snippets.

@raspi
Last active May 5, 2024 22:24
Show Gist options
  • Save raspi/203aef3694e34fefebf772c78c37ec2c to your computer and use it in GitHub Desktop.
Save raspi/203aef3694e34fefebf772c78c37ec2c to your computer and use it in GitHub Desktop.
Enable all advanced power settings in Windows.
# List all possible power config GUIDs in Windows
# Run: this-script.ps1 | Out-File powercfg.ps1
# Then edit and run powercfg.ps1
# (c) Pekka "raspi" Järvinen 2017
$powerSettingTable = Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSetting
$powerSettingInSubgroubTable = Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSettingInSubgroup
Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSettingCapabilities | ForEach-Object {
$tmp = $_.ManagedElement
$tmp = $tmp.Remove(0, $tmp.LastIndexOf('{') + 1)
$tmp = $tmp.Remove($tmp.LastIndexOf('}'))
$guid = $tmp
$s = ($powerSettingInSubgroubTable | Where-Object PartComponent -Match "$guid")
if (!$s) {
return
}
$tmp = $s.GroupComponent
$tmp = $tmp.Remove(0, $tmp.LastIndexOf('{') + 1)
$tmp = $tmp.Remove($tmp.LastIndexOf('}'))
$groupguid = $tmp
$s = ($powerSettingTable | Where-Object InstanceID -Match "$guid")
$descr = [string]::Format("# {0}", $s.ElementName)
$runcfg = [string]::Format("powercfg -attributes {0} {1} -ATTRIB_HIDE", $groupguid, $guid)
Write-Output $descr
Write-Output $runcfg
Write-Output ""
}
@Slach
Copy link

Slach commented Jun 10, 2020

@banicpe @ar-ml and all others who will landing to this page from StackOverflow or google

also helpful
export
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings
and change all
"Attributes"=dword:00000001
to
"Attributes"=dword:00000000

and import PowerSettings back

@Velocet
Copy link

Velocet commented Jun 15, 2020

I have written my own version which works with PowerShell 7 and every Windows version: Unlock-PowerCfg.ps1

# Unlock Power Plans by disabling "Connected Standby"
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Power' -Name 'CSEnabled' -Value 0 -Force

# Unlock hidden options
$PowerSettings = Get-ChildItem -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Power\PowerSettings' -Recurse -Depth 1 | Where-Object { $_.PSChildName -NotLike 'DefaultPowerSchemeValues' -and $_.PSChildName -NotLike '0' -and $_.PSChildName -NotLike '1' }
ForEach ($item in $PowerSettings) { Set-ItemProperty -Path ($item).Replace('HKEY_LOCAL_MACHINE','HKLM:') -Name 'Attributes' -Value 2 -Force }

@nick4fake
Copy link

@Velocet, small fix:

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Power' -Name 'CSEnabled' -Value 0 -Force
    # Unlock hidden options
    $PowerSettings = Get-ChildItem -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Power\PowerSettings' -Recurse -Depth 1 | Where-Object { $_.PSChildName -NotLike 'DefaultPowerSchemeValues' -and $_.PSChildName -NotLike '0' -and $_.PSChildName -NotLike '1' }
    ForEach ($item in $PowerSettings) { Set-ItemProperty -Path ($item).Name.Replace('HKEY_LOCAL_MACHINE','HKLM:') -Name 'Attributes' -Value 2 -Force }

@VLDG2712
Copy link

VLDG2712 commented Feb 3, 2023

god thank you @Velocet @nick4fake guys!!!

@AutomationEngineer0817
Copy link

Thanks @Velocet, your script actually works WIN 11 also, your amazing

@lavinnyv
Copy link

lavinnyv commented Sep 8, 2023

what would i change to DISABLE all advanced power settings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment