July 10th, 2014

PowerTip: Count a Range of Seconds with PowerShell

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to count a range of seconds.

Hey, Scripting Guy! Question How can I use Windows PowerShell to count a range of seconds of increasing duration?

Hey, Scripting Guy! Answer Use the range operator to create a range of numbers, then pipe the results to the ForEach-Object cmdlet
          inside a script block call Start-Sleep:

1..5 | ForEach {Start-Sleep -Seconds $_ ; "$_ seconds"}

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.