No Sleep is a simple PowerShell script that prevents a Windows virtual machine (or physical machine) from entering sleep mode. It's useful for ensuring continuous uptime during long-running tasks, testing environments, or remote access sessions.
- Blocks system sleep (S1/S3/S0 idle)
- Logs activity every minute to a rotating log file
- Logging is capped at 10,000 lines to prevent excessive disk usage.
- Configurable as a scheduled task to auto-start at boot
- Requires no external dependencies
- The script uses native Windows APIs via Add-Type to request the system stay awake.
- Compatible with Windows 10/11 and most Windows Server versions.
-
Open PowerShell as Administrator and run:
Invoke-WebRequest -Uri "https://github.com/marksowell/nosleep/raw/main/nosleep.ps1" -OutFile "$env:USERPROFILE\Desktop\nosleep.ps1"
-
Open PowerShell as Administrator and run:
$scriptPath = "$env:USERPROFILE\Desktop\nosleep.ps1" $me = "$env:USERDOMAIN\$env:USERNAME" $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-WindowStyle Hidden -ExecutionPolicy Bypass -File `"$scriptPath`"" $trigger = New-ScheduledTaskTrigger -AtStartup $principal = New-ScheduledTaskPrincipal -UserId $me -RunLevel Highest Unregister-ScheduledTask -TaskName "PreventS1Sleep" -Confirm:$false -ErrorAction SilentlyContinue Register-ScheduledTask -TaskName "PreventS1Sleep" -Action $action -Trigger $trigger -Principal $principal
-
Start the scheduled task:
Start-ScheduledTask -TaskName "PreventS1Sleep"
-
Verify it’s working:
Get-Content -Tail 5 "$env:USERPROFILE\Desktop\nosleep.log"
Example output:
2025-05-23 14:02:00 - nosleep.ps1 started successfully — power request set 2025-05-23 14:03:00 - Preventing sleep (active)
-
(Optional) Get detailed information:
Get-ScheduledTask -TaskName "PreventS1Sleep" | Get-ScheduledTaskInfo
-
Delete the scheduled task:
Unregister-ScheduledTask -TaskName "PreventS1Sleep" -Confirm:$false
-
Delete the files from your Desktop:
- nosleep.ps1
- nosleep.log