TheGeekery

The Usual Tech Ramblings

PowerShell: Timing Commands

Curious about how long your script took to execute? How about just that cmdlet? Powershell has a built in function for you.

  • Open Powershell command prompt
  • Use the command Measure-Command like so:
1
Measure-Command {c:\scripts\yourscript.ps1}

Enjoy the output broken down by days, hours, minutes, seconds, milliseconds, and ticks.

1
2
3
4
5
6
7
8
9
10
11
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 34
Milliseconds      : 287
Ticks             : 342873445
TotalDays         : 0.000396844265046296
TotalHours        : 0.00952426236111111
TotalMinutes      : 0.571455741666667
TotalSeconds      : 34.2873445
TotalMilliseconds : 34287.3445

The same works for cmdlets too…

1
2
3
4
5
6
7
8
9
10
11
12
13
PS C:\scripts> Measure-Command {Get-Process}

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 6
Ticks             : 65919
TotalDays         : 7.62951388888889E-08
TotalHours        : 1.83108333333333E-06
TotalMinutes      : 0.000109865
TotalSeconds      : 0.0065919
TotalMilliseconds : 6.5919

Comments