PowerTip: Time Parts of PowerShell Scripts

PowerTip: Time Parts of PowerShell Scripts

  • Comments 3
  • Likes

Summary: Learn how to time different parts of your Windows PowerShell scripts.

Hey, Scripting Guy! Question 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?

Hey, Scripting Guy! Answer 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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Very cool, if not a bit shaming to time my scripts.