PowerTip: Measure Performance of PowerShell Command


Summary: Measure how long it takes for a Windows PowerShell command to complete.  

Hey, Scripting Guy! Question If I change one command to try to improve the speed of my Windows PowerShell script , how can I see if
           that command is faster than the one I changed?

Hey, Scripting Guy! Answer Use the Measure-Command cmdlet. For example, to see if Get-Date or [datetime]::now is faster,
           place the command in a script block as shown here:

Measure-Command -Expression {get-date}

Measure-Command -Expression {[datetime]::now}

Comments (2)

  1. roddie digital says:

    Very cool command.

  2. Crackadial says:

    I would suggest to always repeat each measurement at least twice. Command parsing and caching, sometimes even module loading can make a huge difference between invocations. For very simple and fast commands I use loops so the total measured time is in
    the seconds. It’s chance vs statistics.

Skip to main content