In PowerShell, the Start-Sleep
cmdlet is used to pause the execution of a script or command for a specified amount of time.
This can be useful in a variety of situations, such as when you want to wait for a certain event to occur or for a certain amount of time to pass before continuing with the script. Keep in mind that the Start-Sleep
cmdlet is not a replacement for a proper timing mechanism in your script; it simply causes the script to pause for the specified amount of time.
PowerShell start-sleep syntax
Full Command: Start-Sleep
Alias: Sleep
Parameters: -Milliseconds (-m) -Seconds (-s)
Example: start-sleep -s 4
PowerShell sleep examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#Start sleep 1 second, short alias. sleep -s 1 #Start sleep 1 second, full command. start-sleep -Seconds 1 #Start sleep 1 milisecond, short alias. sleep -m 1 #Start sleep 1 milisecond, full command. start-sleep -Milliseconds 1 #Using sleep in a script. In a loop for example. while($True) { $count++ ; Write-host "$Count" ; sleep -s 3 } |