PowerShell – Countdown Timer

email me

clear-host

$Countdown = Get-Date -h 08 -min 06 -s 00

do { $Current = Get-Date -DisplayHint time

"`nThe current time is " + $Current
"counting to " + $Countdown
Start-Sleep -s 1

} while ($Current -lt $Countdown)

Write-Host "Done!"


Output

The current time is 08/14/2019 08:05:54
counting to 08/14/2019 08:06:00

The current time is 08/14/2019 08:05:55
counting to 08/14/2019 08:06:00

The current time is 08/14/2019 08:05:56
counting to 08/14/2019 08:06:00

The current time is 08/14/2019 08:05:58
counting to 08/14/2019 08:06:00

The current time is 08/14/2019 08:05:59
counting to 08/14/2019 08:06:00

The current time is 08/14/2019 08:06:00
counting to 08/14/2019 08:06:00

The current time is 08/14/2019 08:06:01
counting to 08/14/2019 08:06:00

Done!

 

Notes

Get-Date
Start-Sleep
Write-Host

 

tags: PowerShell Loop, PowerShell Date, PowerShell Time, MrNetTek