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.

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,122 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,484 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
{count} votes

6 answers

Sort by: Most helpful
  1. SChalakov 10,261 Reputation points MVP
    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,261 Reputation points MVP
    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