Back to Resources

Level Verified

Windows Disable Sleep on AC Power Script

Created by

Level

Type

Script

Category

Maintenance

Platforms
WindowsApple iOSLinux

Problem Overview

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.

Description

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.

Script

<#
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
}

Use Cases

  • Keeping remote systems awake to maintain uninterrupted access
  • Ensuring virtual machines or servers do not enter sleep mode during critical operations
  • Preventing kiosk or public-facing machines from powering down unexpectedly
  • Maintaining a consistent environment for reliable backup or patch routines

Recommendations

  • Test the script on a non-production device or virtual machine to confirm it applies the settings correctly
  • Use Level Level to run this on new devices or as part of setup to ensure you have consistent management access
  • For recurring adjustments, build an Automation in Level that runs on a schedule to ensure all newly onboarded devices remain awake

FAQ

  • Will this script affect battery settings?
    No. It only targets AC power settings, ensuring it won’t prevent devices from sleeping when running on battery.
  • How do I confirm the script worked?
    The script checks the new setting automatically and displays a success or failure message. You can also run powercfg /QUERY SCHEME_CURRENT SUB_SLEEP to verify manually.
  • Can I revert to the default sleep settings?
    Yes. You can manually adjust power settings in the Windows Control Panel or run powercfg /CHANGE "SCHEME_CURRENT" "SUB_SLEEP" "STANDBYAC" <time_in_minutes> with your preferred timeout value.

Included with this Script:

Below is a list of what you can expect to find when importing this Script.

Script details:

The following data and settings will be imported with your script.

Script Name

Windows - Disable Sleep on AC Power

Description

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.

Language

PowerShell

Timeout (In Seconds)

100

Run As

Local system

Import into Level

Related resources

Explore more automations, scripts, and policies to further enhance your IT operations.

View all resources