How to wait/pause/sleep the script processing in powershell.
Start-Sleep cmdlet is
Syntax:
Start-Sleep [-seconds] int [CommonParameters]
Start-Sleep -milliseconds int [CommonParameters]
There is an alternate way to pause the execution which wait until the user presses a any key.
This can be achieve using the command.
Note: But this commands works in powershell command shell not in powershell ISE.
Also you can wait on the job to finish with a timeout.
Example
$comp = Get-ADComputer -filt * #credentials and AD filter
$cred = Get-Credential PC\administrator #create credentials variable
$session = New-PSSession -cn $comp.name -cred $cred #create session
$job = icm -Session $session -ScriptBlock {gpupdate /force} -AsJob #create job
Wait-Job $job -Timeout 60 #wait job for 60 seconds
Remove-PSSession $session #remove session
Restart-Computer $comp.name