Skip to content

Instantly share code, notes, and snippets.

@0scvr
Created April 13, 2023 16:53
Show Gist options
  • Save 0scvr/7d1aaacb8b2bc86077a1151cd0e3d6df to your computer and use it in GitHub Desktop.
Save 0scvr/7d1aaacb8b2bc86077a1151cd0e3d6df to your computer and use it in GitHub Desktop.
Powershell script to prevent Windows from sleeping
param([int]$minutes=60) # input param, 60 minutes if no value provided
$wsh = New-Object -ComObject WScript.Shell
$a = Get-Date # Current time
$b = $a.AddMinutes($minutes) # Target time
while ($a -lt $b) {
# Send Shift+F15
$wsh.SendKeys('+{F15}')
Start-Sleep -seconds 240 # sleep for 4 minutes
$a = Get-Date
}
# Use it with: powershell.exe -file dontsleep.ps1 -minutes 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment