Skip to content

Instantly share code, notes, and snippets.

@longgiangp
Forked from Velocet/Unlock-PowerCfg.ps1
Last active September 29, 2021 00:09
Show Gist options
  • Save longgiangp/de8a80b0aa98d161eec62f1ef7ded019 to your computer and use it in GitHub Desktop.
Save longgiangp/de8a80b0aa98d161eec62f1ef7ded019 to your computer and use it in GitHub Desktop.
[win] Unlock every Power Plan & Option

This is a fork with fixed ForEach Statement.

Unlock every Power Plan and corresponding option on Windows. Just paste in an elevated PowerShell.

Use this instead of some shady PowerCfg commands or .reg file as this script works even for newer/unknown settings: It will look up the PowerSettings registry hive and just add or change a value (Attributes = 2) on the corresponding option to reveal it.

The OneLiner version is untested but should also work...

Requirements:

  • Windows 7 - 10
  • Elevated PowerShell v2 - v7
#Requires -RunAsAdministrator
if (!$IsLinux -and !$IsMacOS) {
# 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) {
$path = $item -replace "HKEY_LOCAL_MACHINE","HKLM:"; Set-ItemProperty -Path $path -Name 'Attributes' -Value 2 -Force
}
}
gci -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Power\PowerSettings' -Recurse -Depth 1 | ? { $_.PSChildName -NotLike 'DefaultPowerSchemeValues' -and $_.PSChildName -NotLike '0' -and $_.PSChildName -NotLike '1' } | % {sp -Path ($_).Replace('HKEY_LOCAL_MACHINE','HKLM:') -Name 'Attributes' -Value 2 -Force }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment