How to add Sleep to PowerShell Script

If you want to add a sleep (delay) to your PowerShell script, you need to make use of the Start-Sleep cmdlet,

Let's take a look at a few examples.


Example 1: One-Liner Sleep

    echo "Sleeping for 10 seconds"; Start-Sleep -Seconds 10; echo "Done!"

    Sleeping for 10 seconds
    Done!


Example 2: Sleep with Script

    $numbers = 1..10
    
    foreach ($num in $numbers) {
        # Sleep for 1 seconds
        Start-Sleep -Seconds 1
        Write-Host $num
    }
    
    ./powershell-sleep-script.ps1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
PowerShell Sleep Script Example

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!