Back to Blog
Guide

Keep a Windows PC Awake With PowerShell: Two Tested Scripts

Keep Windows awake from PowerShell without admin rights: call SetThreadExecutionState to block sleep and screen-off, or press F15 every minute to reset the idle timer. The scripts, how to run and stop them, a powercfg one-liner, and what each does for Teams and Slack.

Slack Green Team
September 23, 2026
October 8, 2026
5 min read
Share:
windows
powershell
remote work

You can keep a Windows PC awake from PowerShell without admin rights in two ways. The clean one calls the Windows API SetThreadExecutionState to tell Windows the system and display are needed, which blocks sleep and screen-off while the script runs and sends no input. The other presses the F15 key every minute with SendKeys, which resets the idle timer, so it also keeps Microsoft Teams green. The F15 script should keep the Slack desktop app active too, because the app reads the same idle timer every 10 seconds (Slack desktop 4.52.178 code, checked 7 Oct 2026); we have not timed it on Windows. The SetThreadExecutionState script sends no input, so Slack still goes away after 10 minutes.

A script on the PC cannot keep Slack green while the PC is locked, asleep or off; how to keep Slack active has the options that can.

Script 1: block sleep with SetThreadExecutionState

This asks Windows to keep the system and display on, the same mechanism video players use. It creates no keyboard or mouse input.

# keepawake.ps1 - keeps Windows and the display awake until you press Ctrl+C
$sig = '[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint esFlags);'
$power = Add-Type -MemberDefinition $sig -Name 'Power' -Namespace 'Win32' -PassThru

# ES_CONTINUOUS (0x80000000) | ES_SYSTEM_REQUIRED (0x1) | ES_DISPLAY_REQUIRED (0x2)
$null = $power::SetThreadExecutionState([uint32]2147483651)
Write-Host "Keeping this PC awake. Press Ctrl+C to stop."
try {
    while ($true) { Start-Sleep -Seconds 60 }
} finally {
    $null = $power::SetThreadExecutionState([uint32]2147483648)   # ES_CONTINUOUS: back to normal
}

Check it works: in a second PowerShell window run powercfg /requests. PowerShell appears under DISPLAY and SYSTEM while the script runs.

Script 2: press F15 every minute

F15 is a key no keyboard has, so most apps ignore it, but Windows counts it as input.

# f15.ps1 - presses F15 once a minute until you press Ctrl+C
$shell = New-Object -ComObject WScript.Shell
while ($true) {
    $shell.SendKeys('{F15}')
    Start-Sleep -Seconds 60
}

Because it is input, it resets the idle timer that Teams uses, so Teams usually stays Available. It sends the key to whatever window is in focus. Software input like this is marked as injected by Windows and can be seen by monitoring tools; see can a mouse jiggler be detected. A Teams-only version with Num Lock and work-hours variants is in PowerShell script to keep Teams active. To build a jiggler that moves the pointer instead, in Python, AutoHotkey or on a $5 USB board, see DIY mouse jiggler. The same two scripts written in AutoHotkey v2 are in AutoHotkey script to keep your computer awake.

How to run and stop a PowerShell keep-awake script

Run a keep-awake script: save, open PowerShell, run with Bypass, stop with Ctrl+C

  • Paste a script into Notepad and save it as keepawake.ps1.
  • Open PowerShell (no admin needed) and go to the folder.
  • Run: powershell -ExecutionPolicy Bypass -File .\keepawake.ps1
  • Press Ctrl+C or close the window to stop. Windows goes back to its normal power settings.

If your company blocks PowerShell scripts, do not work around the policy. Use the settings or tools in keep a work computer awake without admin rights instead. Inside a Remote Desktop session the F15 script also resets the session idle timer; the policy side of RDP timeouts is in how to keep a Remote Desktop session active.

Never appear "away" on Slack again

Cloud-based. No downloads. Works 24/7 even when your laptop is off.

Batch and cmd: change the timeouts instead

To stop sleep while plugged in, without a running script:

powercfg /change standby-timeout-ac 0
powercfg /change monitor-timeout-ac 0

0 means never. Set them back later with the minutes you want, for example powercfg /change standby-timeout-ac 30. On a managed PC these may be locked by policy. For the display timer in seconds and the lock screen timer, see how to change the screen timeout on Windows 11.

Keep the PC awake until a download finishes

Sleep stops a download. Windows parks the disk and cuts the network, Steam shows the download as paused until the PC wakes, and a browser download often fails with a network error. A dark screen or a locked screen stops nothing, because the computer keeps running. So for a download you only need to block sleep, and the display can still turn off.

StateDownload keeps going?
Awake, screen off or lockedYes
Sleep, hibernate or shut downNo
Laptop lid closed, default actionNo, the lid starts sleep

This version of Script 1 drops the display flag and lets Windows sleep again once the folder has had no new writes for 5 minutes:

# awake-while-downloading.ps1 - no sleep while files in the folder are still changing
param(
    [string]$Folder = "$env:USERPROFILE\Downloads",
    [int]$QuietMinutes = 5
)
$sig = '[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint esFlags);'
$power = Add-Type -MemberDefinition $sig -Name 'Power' -Namespace 'Win32' -PassThru

# ES_CONTINUOUS (0x80000000) | ES_SYSTEM_REQUIRED (0x1): no sleep, the screen may still turn off
$null = $power::SetThreadExecutionState([uint32]2147483649)
try {
    do {
        Start-Sleep -Seconds 60
        $since = (Get-Date).AddMinutes(-$QuietMinutes)
        $busy = Get-ChildItem $Folder -Recurse -File -ErrorAction SilentlyContinue |
            Where-Object { $_.LastWriteTime -gt $since } | Select-Object -First 1
    } while ($busy)
} finally {
    $null = $power::SetThreadExecutionState([uint32]2147483648)   # back to normal
}
Write-Host "No writes for $QuietMinutes minutes. Sleep is allowed again."

Start it after the download begins. Steam does not block sleep on its own, so point the script at Steam's download folder and leave Steam running:

powershell -ExecutionPolicy Bypass -File .\awake-while-downloading.ps1 -Folder "C:\Program Files (x86)\Steam\steamapps\downloading"

On a Mac the same idea takes two lines in Terminal. caffeinate -i blocks idle sleep, and -w $$ ends the hold when the shell exits:

caffeinate -i -w $$ &
while [ -n "$(find ~/Downloads -type f -mmin -5 | head -n 1)" ]; do sleep 60; done

We ran it on macOS 26.5.2 on 4 October 2026 with a 1-minute quiet time on a test folder. While a file was being written, pmset -g assertions listed PreventUserIdleSystemSleep named: "caffeinate command-line tool". After the writes stopped, the loop ended and the hold was gone. The flags are explained in caffeinate on Mac.

Which script to use

ScriptStops sleepTeams greenSlack active
SetThreadExecutionStateYesNoNo
F15 every minuteYesUsuallyShould, desktop app, while unlocked
powercfg timeoutsYes, plugged inNoNo
Server-side presence scheduleNot neededNo, Slack onlyYes

For Teams timings see how long before Teams shows you as Away. For Slack, the rules are in how long does Slack stay active, and Windows options in keep Slack active on Windows. The ready-made app equivalent of script 1 is PowerToys Awake; see does PowerToys Awake keep Slack active.

FAQ

How do I keep my computer awake with PowerShell?

Run a script that calls SetThreadExecutionState with the system and display flags, or one that presses F15 every minute.

Does a PowerShell script keep Teams green?

The F15 script usually does, because it is input. The SetThreadExecutionState script does not.

Does a PowerShell script keep Slack active?

The F15 script resets the Windows idle timer, which the Slack desktop app reads, so it should, while the PC is unlocked. The SetThreadExecutionState script does not.

Do I need admin rights?

No, unless your company blocks PowerShell scripts.

How do I stop the script?

Press Ctrl+C or close the PowerShell window.

Always Active

Stop Jiggling Your Mouse.

Join hundreds of remote workers who never worry about their Slack status. Set it up once, stay green forever.

Related Articles

Guide

How to See All Your DMs in Slack, Including the Hidden Ones

The DMs tab lists your direct messages with people. App DMs, Slackbot and DMs with deleted accounts sit elsewhere. We compared the tab with the full list the Slack API returned.

Slack Green Team
Guide

Slack Images Not Showing? 5 Causes We Reproduced

We uploaded images to a Slack test channel and then switched each image setting off, ran /collapse, and posted from a bot that was not in the channel. Five causes, each reproduced.

Slack Green Team
Guide

How to Message Yourself on Slack (and What It Notifies)

Your own name under Direct messages opens a private DM with yourself. We sent it a note, a file, a scheduled message and a reminder, and checked which ones raised a badge.

Slack Green Team