Measure the time a script in powershell will take to run

Ed7 96 Reputation points
2021-12-07T10:05:43.833+00:00

Hello,

Could you tell me how can I check the estimated time a a script will take to run?
I have used this so far but it seems failing giving me a wrong estimated time.
After running a script it toke less time than the estimate time

Measure-Command -Expression{
powershell.exe "C:\Pathtoscript\Myscript.ps1"}

Thank you in advance.

Microsoft 365 and Office Development Other
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
{count} votes

6 answers

Sort by: Most helpful
  1. SChalakov 10,576 Reputation points MVP Volunteer Moderator
    2021-12-07T10:55:39.643+00:00

    Hi @Ed7 ,

    you are actually using one of the recommended methods, maybe you are having some deltas in the data, hence the differences between the actual and measured execution time. Still there are two other way to check if the measurement you do is correct, Adma the Automator lists those here:

    3 ways to measure your Powershell script's speed
    https://www.pluralsight.com/blog/tutorials/measure-powershell-scripts-speed

    I hope I could help ypou out. Regards,

    ----------

    If my reply was helpful please don't forget to upvote and/or accept as answer, thank you!
    Regards,
    Stoyan

    0 comments No comments

  2. Ed7 96 Reputation points
    2021-12-07T11:05:33.393+00:00

    Hi @SChalakov ,

    Thank you for your response.

    When I run the script this is what I get and its estimated time:

    155580-image.png

    Then when it completes it does tell me how long it took

    155519-image.png

    Not to mention that with this command it will use the full RAM available

    Measure-Command -Expression{
    powershell.exe "C:\Pathtoscript\Myscript.ps1"}

    So something is not right

    0 comments No comments

  3. SChalakov 10,576 Reputation points MVP Volunteer Moderator
    2021-12-07T11:17:50.95+00:00

    Hi,

    Could it be be, because of the "&" in the name of the script? Can you please remove it and try again?
    Did you also test the other options?

    Regards,
    Stoyan

    0 comments No comments

  4. Ed7 96 Reputation points
    2021-12-07T11:34:27.75+00:00

    HI,

    Yes I have removed the "&" and it takes longer than usual to run the script. and still uses a lot of resources and takes a lot of time

    155620-image.png

    I wonder if its because I am measureing the script I am running or not. But yesterday when I tried it did not behave as it is today

    0 comments No comments

  5. Ed7 96 Reputation points
    2021-12-07T12:08:53.997+00:00

    Well it seems that is not giving me the error but the estimate time is still not right. I changed the cmmand for Measure-Command {"C:\Pathtoscript\Myscript.ps1"}

    Need to understant why is giving the wrong time.

    155691-image.png

    And it took me

    155627-image.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.