{"id":1318,"date":"2014-05-18T11:59:00","date_gmt":"2014-05-18T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/05\/18\/powertip-time-parts-of-powershell-scripts\/"},"modified":"2014-05-18T11:59:00","modified_gmt":"2014-05-18T11:59:00","slug":"powertip-time-parts-of-powershell-scripts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-time-parts-of-powershell-scripts\/","title":{"rendered":"PowerTip: Time Parts of PowerShell Scripts"},"content":{"rendered":"<p><b>Summary<\/b>: Learn how to time different parts of your Windows PowerShell scripts.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;How can I use Windows PowerShell to find which parts of my script are taking the longest <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to complete so I can focus on improving them?<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Use the&nbsp;<b>Measure-Command<\/b>&nbsp;cmdlet to time any section of script in between two curly braces:<\/p>\n<p style=\"margin-left:120px\">Measure-Command {Start-Sleep -Seconds 5}<\/p>\n<p style=\"margin-left:120px\">Windows PowerShell automatically outputs the time for that section of script:<\/p>\n<p style=\"margin-left:120px\">Days&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0<\/p>\n<p style=\"margin-left:120px\">Hours&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0<\/p>\n<p style=\"margin-left:120px\">Minutes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0<\/p>\n<p style=\"margin-left:120px\">Seconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 5<\/p>\n<p style=\"margin-left:120px\">Milliseconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 7<\/p>\n<p style=\"margin-left:120px\">Ticks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 50072804<\/p>\n<p style=\"margin-left:120px\">TotalDays&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 5.79546342592593E-05<\/p>\n<p style=\"margin-left:120px\">TotalHours&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0.00139091122222222<\/p>\n<p style=\"margin-left:120px\">TotalMinutes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0.0834546733333333<\/p>\n<p style=\"margin-left:120px\">TotalSeconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 5.0072804<\/p>\n<p style=\"margin-left:120px\">TotalMilliseconds : 5007.2804<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to time different parts of your Windows PowerShell scripts. &nbsp;How can I use Windows PowerShell to find which parts of my script are taking the longest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to complete so I can focus on improving them? &nbsp;Use the&nbsp;Measure-Command&nbsp;cmdlet to time any section of script in between two curly [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[512,56,356,3,45],"class_list":["post-1318","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-dan-sheehan","tag-guest-blogger","tag-powertip","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to time different parts of your Windows PowerShell scripts. &nbsp;How can I use Windows PowerShell to find which parts of my script are taking the longest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to complete so I can focus on improving them? &nbsp;Use the&nbsp;Measure-Command&nbsp;cmdlet to time any section of script in between two curly [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=1318"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1318\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=1318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}