Back to Resources
Level
Script
Maintenance
Many Windows devices enter sleep mode by default, even when connected to a power source, causing unexpected downtime and halting critical processes. This script addresses the frustration of losing remote access, interrupting server tasks, or missing automated backups by ensuring devices stay fully operational while on AC power.
This script leverages the built-in Windows powercfg
utility to set the sleep timeout value on AC power to zero, effectively disabling sleep mode. Once it makes the change, it validates the current setting to confirm sleep has indeed been disabled, offering peace of mind that the adjustment is successful.
<#
This resource is provided as a convenience for Level users. We cannot
guarantee it will work in all environments. Please test before deploying
to your production environment. We welcome contributions to our community
library
Level Library
https://level.io/library/script-windows-disable-sleep-on-ac-power
#>
# Disable sleep on AC power
Write-Host "Disabling sleep on AC power..." -ForegroundColor Green
# Set the AC power setting for sleep timeout to never (0)
powercfg /CHANGE "SCHEME_CURRENT" "SUB_SLEEP" "STANDBYAC" 0
# Verify the change
$acSleepTimeout = powercfg /QUERY SCHEME_CURRENT SUB_SLEEP | Select-String -Pattern "STANDBYAC.*(Current Setting)"
if ($acSleepTimeout -match "0") {
Write-Host "Sleep on AC power has been disabled successfully." -ForegroundColor Green
} else {
Write-Host "Failed to disable sleep on AC power. Please check your permissions or Power Plan settings." -ForegroundColor Red
}
powercfg /QUERY SCHEME_CURRENT SUB_SLEEP
to verify manually.powercfg /CHANGE "SCHEME_CURRENT" "SUB_SLEEP" "STANDBYAC" <time_in_minutes>
with your preferred timeout value.Windows - Disable Sleep on AC Power
This script disables sleep mode on AC power by setting the sleep timeout to "never" (0) using the powercfg command. It then verifies the change and provides feedback on whether the operation was successful or if there were issues.
PowerShell
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.