PowerTip: Count a Range of Seconds with PowerShell

Doctor Scripto

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"}

0 comments

Discussion is closed.

Feedback usabilla icon