PowerShell Genie

Start-Sleep

Use Start-Sleep to pause a script for a set time — waiting for a service to start, spacing out retries, or throttling a loop.

Command 3 min read PowerShell 7 on Windows

Documentation: Microsoft Learn — start-sleep

Syntax

1PS> Start-Sleep [-Seconds] <Double> [<CommonParameters>]
2PS> Start-Sleep -Milliseconds <Int32> [<CommonParameters>]

Try it

Windows PowerShell

PowerShell example · browser support is limited.

Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

Interactive simulation · fictional data

Examples

Pause for five seconds

1PS> Start-Sleep -Seconds 5
Show reference output

Illustrative output · values vary by environment

(pauses for 5 seconds, then continues)

Pause for half a second in a loop

1PS> for ($i = 1; $i -le 3; $i++) { Write-Host "Tick $i" Start-Sleep -Milliseconds 500 }
Show reference output

Illustrative output · values vary by environment

Tick 1
Tick 2
Tick 3

Retry a flaky operation up to five times

1PS> $attempt = 0 while ($attempt -lt 5) { try { Invoke-WebRequest https://example.com -UseBasicParsing; break } catch { $attempt++; Start-Sleep -Seconds (5 * $attempt) } }
Show reference output

Illustrative output · values vary by environment

(retries with 5, 10, 15 second waits)

Parameters

Parameter definitions:

  • -Seconds — Seconds to pause. Accepts decimals, so 0.5 means half a second.
  • -Milliseconds — Milliseconds to pause. Use this for sub-second waits.

Microsoft Learn — start-sleep

Sleep is a guess — prefer waiting for a real condition

A fixed sleep assumes the thing you wait for finishes in exactly that time. On a slow day it finishes late and your script fails; on a fast day you waste time. Where possible, poll for the real condition instead: loop until (Get-Service Spooler).Status -eq 'Running' with a short sleep between checks and a maximum attempt count.

Back-off retries beat fixed retries. Waiting 5 seconds, then 10, then 15 gives a struggling service room to recover without hammering it. Cap the attempts so a permanently dead service fails fast instead of retrying forever.

In PowerShell 7, -Seconds accepts fractional values. In Windows PowerShell 5.1 it only accepts whole seconds, so use -Milliseconds 500 there for half-second waits.

Show progress while waiting with Write-Progress

Check a service state with Get-Service

Updated 25 October 2026. Browser outputs are fictional; check the installed module help for your environment.

Recap

Start-Sleep Use Start-Sleep to pause a script for a set time — waiting for a service to start, spacing out retries, or throttling a loop.

Next: Rename Item
Genie guideStart-Sleep

Start-Sleep pauses execution for seconds or milliseconds. Learn the retry-loop pattern, why you should never sleep in a tight loop without a limit, and how to wait for a service instead of guessing. The console below is pre-loaded — run it, then change a value and run it again.