Powershell

One line countdown timer

This is the shortest one line countdown timer for pausing a script I can come up with. It uses a little-known ping trick to create a 1s gap. It wraps this around the built-in powershell write-progress command. It can be used in place of the DOS "timeout /t" command.

$wait=5; for($i=1; $i -le $wait; $i++) {ping localhost -n 2 -w 1000 > $null; Write-Progress -Activity "Waiting" -secondsRemaining ($wait-$i)}

Or if you'd like to display a progress bar:

$wait=5; for($i=1; $i -le $wait; $i++) { ping localhost -n 2 -w 1000 > $null; Write-Progress -Activity ("Waiting " + ($wait-$i+1) +" seconds") -PercentComplete ($i / $wait * 100) }