Powershell show elapsed time


SUBMITTED BY: Guest

DATE: Nov. 14, 2013, 7:04 a.m.

FORMAT: Text only

SIZE: 855 Bytes

HITS: 1181

  1. Powershell show elapsed time
  2. $Time = [System.Diagnostics.Stopwatch]::StartNew()
  3. while ($true) {
  4. $CurrentTime = $Time.Elapsed
  5. write-host $([string]::Format("`rTime: {0:d2}:{1:d2}:{2:d2}",
  6. $CurrentTime.hours,
  7. $CurrentTime.minutes,
  8. $CurrentTime.seconds)) -nonewline
  9. sleep 1
  10. if ($Host.UI.RawUI.KeyAvailable -and ("q" -eq $Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").Character)) {
  11. Write-Host "Exiting now"
  12. break;
  13. }
  14. $Time = [System.Diagnostics.Stopwatch]::StartNew()
  15. while ($NoEvent) {
  16. $CurrentTime = $Time.Elapsed
  17. write-host $([string]::Format("`rTime: {0:d2}:{1:d2}:{2:d2}",
  18. $CurrentTime.hours,
  19. $CurrentTime.minutes,
  20. $CurrentTime.seconds)) -nonewline
  21. sleep 1
  22. #Handle event
  23. if(event){$NoEvent = false}
  24. }

comments powered by Disqus