Summary: Learn how to time different parts of your Windows PowerShell scripts.
How can I use Windows PowerShell to find which parts of my script are taking the longest
to complete so I can focus on improving them?
Use the Measure-Command cmdlet to time any section of script in between two curly braces:
Measure-Command {Start-Sleep -Seconds 5}
Windows PowerShell automatically outputs the time for that section of script:
Days : 0
Hours : 0
Minutes : 0
Seconds : 5
Milliseconds : 7
Ticks : 50072804
TotalDays : 5.79546342592593E-05
TotalHours : 0.00139091122222222
TotalMinutes : 0.0834546733333333
TotalSeconds : 5.0072804
TotalMilliseconds : 5007.2804