PowerShell provides the Start-Sleep
command in order to wait for the command line interface for the specified time. The wait time can be milliseconds, seconds, minutes, hours, etc. The Start-Sleep command simply accepts seconds or milliseconds as parameters but they can be used to express minutes and hours. In this tutorial, we examine how to wait in PowerShell using the Start-Sleep command.
Wait For 1 Second
In the following example, we wait for 1 second by using the -Seconds
parameter and providing 1 to it.
PS> Start-Sleep -Seconds 1
Wait for 0.5 Seconds
We can wait for 0.5 seconds using the -Seconds like below.
PS> Start-Sleep -Seconds 0.5
Wait For Milliseconds
The Start-Sleep command can be also used to wait for milliseconds by providing the milliseconds using the -Milliseconds
. In the following example we wait for 50 milliseconds.
PS> Start-Sleep -Milliseconds 50
Wait For User Input
The Read-Host
command is used to get user input via the command line interface. The console waits until the user provides the input and press enter which waits for the command line interface too. We can use it to wait until the user input.
PS> Read-Host -Prompt "Get me some input..."