{"id":510,"date":"2014-11-16T15:17:43","date_gmt":"2014-11-16T20:17:43","guid":{"rendered":"http:\/\/adsecurity.org\/?p=510"},"modified":"2014-11-13T22:05:15","modified_gmt":"2014-11-14T03:05:15","slug":"powershell-101-easy-script-timing","status":"publish","type":"post","link":"https:\/\/adsecurity.org\/?p=510","title":{"rendered":"PowerShell 101: Easy Script Timing"},"content":{"rendered":"<p>There are times when you want to know how long it takes for a script to run. One of the Measure-* cmdlets can be useful, but there is a simpler way to time how long it takes to run a script (or piece of code).<br \/>\nThe StopWatch .NET method is an ideal method for script timing.<\/p>\n<p>More info on using the StopWatch .Net method:<br \/>\n<a href=\"http:\/\/technet.microsoft.com\/en-us\/magazine\/2009.03.heyscriptingguy.aspx\" target=\"_blank\">http:\/\/technet.microsoft.com\/en-us\/magazine\/2009.03.heyscriptingguy.aspx<\/a><\/p>\n<blockquote><p># START OF SCRIPT<br \/>\n$CurrentUserName = $env:UserName<br \/>\n$ScriptProcessStartTime = Get-Date<br \/>\nwrite-output &#8220;&#8221; `r<br \/>\nwrite-output &#8220;Script initialized by $CurrentUserName and started processing at $ScriptProcessStartTime `r &#8221;<br \/>\n$ScriptTimer = [System.Diagnostics.Stopwatch]::StartNew()<br \/>\nwrite-output &#8220;&#8221; `r<\/p>\n<p>## SCRIPT BODY<\/p>\n<p>## END OF SCRIPT<br \/>\n$ScriptProcessEndTime = Get-Date<br \/>\nwrite-output \u201cScript started processing at $ScriptProcessStartTime and completed at $ScriptProcessEndTime.\u201d `r<br \/>\nwrite-host \u201cTotal Processing Time: $($ScriptTimer.Elapsed.ToString())\u201d<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are times when you want to know how long it takes for a script to run. One of the Measure-* cmdlets can be useful, but there is a simpler way to time how long it takes to run a script (or piece of code). The StopWatch .NET method is an ideal method for script &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/adsecurity.org\/?p=510\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[22,275,274],"class_list":["post-510","post","type-post","status-publish","format-standard","hentry","category-powershell","tag-powershellcode","tag-powershelltimer","tag-scripttimer","item-wrap"],"_links":{"self":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=510"}],"version-history":[{"count":1,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/510\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/510\/revisions\/511"}],"wp:attachment":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}