PowerTip: Count a Range of Seconds with PowerShell

PowerTip: Count a Range of Seconds with PowerShell

  • Comments 9
  • Likes

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • thank you Scripting Guy! Blog

    Learn about Windows PowerShell

  • How do I stop long running scripts?

  • can you given to me of some detail and some information, please. Thank you

  • "Long running script" error messages are specific to Internet Explorer. These messages are generally intended for developers who are testing and building a website You should be able to get rid of them by disabling certain browser settings:
    Open Internet Explorer
    Click the 'Tools' menu, and then select 'Internet Options'
    Click the 'Advanced' tab, select the 'Disable script debugging (Internet Explorer)' and 'Disable script debugging (Other)' check boxes
    Clear the 'Display a notification about every script e

  • Sometimes, a webpage contains script that takes an unusually long time to run. If you are scripting an ActiveX control on a webpage to transfer a very large file or run a large database query, this often causes a significantly long delay. Internet Explorer 3.02 detects the long delay, and prompts the user with a dialog box that reads as follows:
    This page contains a script which is taking an unusually long time to finish. To end this script now, click Cancel.
    The equivalent message box for Internet Explor

  • Because some scripts may take a long time to run, prompts the user to decide whether to continue working with slow scripts in Internet Explorer. Some tests and performance tests may use scripts that take a long time to run. Therefore you may want to increase the time it takes before the message box appears. In Internet Explorer script timeout value is changed on specific client computers by changing an entry in the registry.

  • This mechanism is used to stop the returned script running in an endless loop or otherwise perform slowly.

    In Internet Explorer 3.02, can this message box displayed on computers running Windows 95. Version 3.02 browser looking specifically to see if the thread script has pumped some windows messages in the last five seconds. You can not override this timeout for Internet Explorer 3.02. If you use an ActiveX control with long blocking operations should the ActiveX control used either an event mechanism and

  • Fix it for me

    To fix this problem automatically, click the Fix button or link, click Run in the File Download dialog box and follow the steps in the Fix it wizard.
    Fix this problem
    Fix this problem
    Microsoft Fix it 50403

  • The script seems to run longer than 5 seconds and surely does not count every 1 second.

    Here some results from measure-command {1..5 | ForEach {Start-Sleep -Seconds $_ ; "$_ seconds"}}
    Days : 0
    Hours : 0
    Minutes : 0
    Seconds : 14
    Milliseconds : 988
    Ticks : 149885751
    TotalDays : 0.0001734788
    TotalHours : 0.0041634930
    TotalMinutes : 0.249809585
    TotalSeconds : 14.9885751
    TotalMilliseconds : 14988.5751

    Is PowerShell so slow ?