{"id":52883,"date":"2009-07-23T00:01:00","date_gmt":"2009-07-23T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/07\/23\/hey-scripting-guy-how-can-i-test-the-efficacy-of-my-script-modifications\/"},"modified":"2009-07-23T00:01:00","modified_gmt":"2009-07-23T00:01:00","slug":"hey-scripting-guy-how-can-i-test-the-efficacy-of-my-script-modifications","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-test-the-efficacy-of-my-script-modifications\/","title":{"rendered":"Hey, Scripting Guy! How Can I Test the Efficacy of My Script Modifications?"},"content":{"rendered":"<h2><font size=\"1\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\">Hey Scripting Guy! I have a script that I wrote, and I am interested in modifying it to try and make it run faster. I know I can use the <b>Measure-Object<\/b> Windows PowerShell cmdlet, but I want to run the script several times and get the average time it takes for each script to run. This task sounds like it might be a bit more complicated than I can handle because I am just beginning to learn Windows PowerShell. Could you possibly lend a hand?<\/p>\n<p class=\"MsoNormal\">&#8212; JH<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\">Hello JH, <\/p>\n<p class=\"MsoNormal\">It is late at night on a Saturday night, and I am finishing up the Hey, Scripting Guy! articles for the week that Craig will be on vacation. You see, Craig and I decided to write ahead so there would not be a disruption while we take our vacations. The Scripting Wife and I leave tomorrow morning to go to New York City for a week of shows and museums. Craig goes on vacation the following week (he&rsquo;ll be running with the vampires on the Olympic Peninsula). Because it is rather late, I am drinking a nice ginger tea. When I make ginger tea, I use a piece of fresh ginger root, a stalk of lemongrass, and a teaspoon of orange blossom honey. I put everything in my tea pot and let it steep for 15 minutes before drinking. It is very relaxing and goes well with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dave_Brubeck\"><font face=\"arial,helvetica,sans-serif\">Dave Brubeck<\/font><\/a>. Because I am mellow, relaxed, and looking forward to a week of Broadway shows and museums, I am especially susceptible to suggestion. I will be glad to lend you a hand. The Test-TwoScripts.ps1 script, which I wrote for you, will allow you to test the performance of two scripts and will give you the results in a log file if you desire logged results. There is also a provision that will allow you to run your scripts multiple times to provide you with an average running time. <\/p>\n<p class=\"MsoNormal\">The complete Test-TwoScripts.ps1 script is seen here. <\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>Test-TwoScripts.ps1<\/p>\n<p><\/strong><\/p>\n<p class=\"CodeBlockScreened\"><font size=\"1\"><font><font face=\"Lucida Sans Typewriter\">Param(<br><span>&nbsp; <\/span>[string]$baseLineScript,<br><span>&nbsp; <\/span>[string]$modifiedScript,<br><span>&nbsp; <\/span>[int]$numberOfTests = 20,<br><span>&nbsp; <\/span>[switch]$log<br>) #end param<\/p>\n<p>Function Test-Scripts<br>{<br><span>&nbsp; <\/span>Param(<br><span>&nbsp; <\/span>[string]$baseLineScript,<br><span>&nbsp; <\/span>[string]$modifiedScript,<br><span>&nbsp; <\/span>[int]$numberOfTests,<br><span>&nbsp; <\/span>[switch]$log<br>) #end param<br><span>&nbsp;<\/span>Measure-Command -Expression { $baseLineScript }<br><span>&nbsp;<\/span>Measure-Command -Expression { $modifiedScript }<br>} #end Test-Scripts function<\/p>\n<p>Function Get-Change($baseLine, $modified)<br>{<br><span>&nbsp; <\/span>(($baseLine &#8211; $modified)\/$baseLine)*100<br>} #end Get-Change function<\/p>\n<p>Function Get-TempFile<br>{<br><span>&nbsp;<\/span>[io.path]::GetTempFileName()<br>} #end Get-TempFile function<\/p>\n<p># *** Entry Point To Script<br>if($log) { $logFile = Get-TempFile }<br>For($i = 0 ; $i -le $numberOfTests ; $i++)<br>{<br><span>&nbsp;<\/span>&#8220;Test $i of $numberOfTests&#8221; ; start-sleep -m 50 ; cls<br><span>&nbsp;<\/span>$results= Test-Scripts -baseLineScript $baseLineScript -modifiedScript $modifedScript<br><span>&nbsp;<\/span>$baseLine += $results[0].TotalSeconds<br><span>&nbsp;<\/span>$modified += $results[1].TotalSeconds<br><span>&nbsp;<\/span>If($log)<br><span>&nbsp; <\/span>{<br><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8220;$baseLineScript run $i of $numberOfTests $(get-date)&#8221; &gt;&gt; $logFile<br><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$results[0] &gt;&gt; $logFile<br><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8220;$modifiedScript run $i of $numberOfTests $(get-date)&#8221; &gt;&gt; $logFile<br><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$results[1] &gt;&gt; $logFile<br><span>&nbsp; <\/span>} #if $log<br>} #for $i <\/p>\n<p>&#8220;Average change over $numberOfTests tests&#8221;<br>&#8220;BaseLine: $baseLineScript average Total Seconds: $($baseLine\/$numberOfTests)&#8221;<br>&#8220;Modified: $modifiedScript average Total Seconds: $($modified\/$numberOfTests)&#8221;<br>&#8220;Percent Change: &#8221; + &#8220;{0:N2}&#8221; -f (Get-Change -baseLine $baseLine -modified $modified)<br>if($log)<br>{<br><span>&nbsp;<\/span>&#8220;Average change over $numberOfTests tests&#8221; &gt;&gt; $logFile<br><span>&nbsp;<\/span>&#8220;BaseLine: $baseLineScript average Total Seconds: $($baseLine\/$numberOfTests)&#8221; &gt;&gt; $logFile<br><span>&nbsp;<\/span>&#8220;Modified: $modifiedScript average Total Seconds: $($modified\/$numberOfTests)&#8221; &gt;&gt; $logFile<br><span>&nbsp;<\/span>&#8220;Percent Change: &#8221; + &#8220;{0:N2}&#8221; -f (Get-Change -baseLine $baseLine -modified $modified) &gt;&gt; $logFile<br>} #if $log<br>if($log) { Notepad $logFile }<\/p>\n<p><\/font><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The first thing we do in the Test-TwoScripts.ps1 script is create the command-line parameters. The first parameter, <b>baseLineScript<\/b>, is the path to the script that will be the baseline for comparison. Typically this is the script you used before you modified it. The second parameter is <b>modifiedScript<\/b>, and it is the script whose changes you wish to evaluate. Note that these two scripts do not need to be related to one another. The third parameter is the <b>numberOfTests<\/b> parameter. This number controls how many times the scripts will be run. This is because when testing, a script may run faster or slower on any given run. At times this may be due to files caching or other performance enhancements offered by the operating system, but at other times the difference may be due to resource contention or other anomalies. By running the scripts several times and averaging the results, a more accurate picture of the performance of the scripts can be gained. The last parameter is the switched log parameter. When the log parameter is present, it causes the script to write the performance information to a temporary text file that is displayed at the end of the completion of the script. The <b>Param<\/b> section of the script is seen here:<\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">Param(<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>[string]$baseLineScript,<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>[string]$modifiedScript,<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>[int]$numberOfTests = 20,<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>[switch]$log<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">) #end param<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The <b>test-Scripts<\/b> function is used to call the <b>Measure-Command<\/b> cmdlet for each of the two scripts to be tested. The <b>Param<\/b> section of the function receives two inputs: the <b>baseLineScript<\/b> parameter and the <b>modifiedScript<\/b> parameter. These were cut and pasted from the <b>Param<\/b> section to the script, because it was easier than typing everything a second time. Cutting and pasting the parameters also ensures that you avoid typing errors. This is shown here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">Function Test-Scripts<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">{<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>Param(<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>[string]$baseLineScript,<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>[string]$modifiedScript<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">) #end param<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">After the parameters for the <b>Test-Scripts<\/b> function has been created, it is time to call the <b>Measure-Command<\/b> cmdlet. The <b>Measure-Command<\/b> cmdlet is called twice. The first time, the baseline script is passed to the expression parameter of the <b>Measure-Command<\/b> cmdlet. The string that is passed to the <b>$baseLineScript<\/b> parameter includes the full path to the script as well as all parameters the script requires to successfully execute. The second <b>Measure-Command<\/b> cmdlet is called to evaluate the performance of the modified script. The path to the modified script as well as the parameters required to set up the command is passed to the expression parameter of the <b>Measure-Command<\/b> cmdlet. This is seen here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>Measure-Command -Expression { $baseLineScript }<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>Measure-Command -Expression { $modifiedScript }<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">} #end Test-Scripts function<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The <b>Get-Change<\/b> function is used to calculate the percentage increase or decrease in total running time between the baseline script and the modified script. The baseline parameter contains the total number of seconds the baseline script required to execute. The modified parameter contains the total number of seconds the modified script required to execute. It the <b>Test-Scripts<\/b> function was called several times (due to script performing multiple tests), the <b>$baseLine<\/b> variable and the <b>$modified<\/b> variable will contain the cumulative number of seconds running time from the entire series of tests. To calculate the percentage increase or decrease in total running time, the total number of seconds contained in the <b>$modified<\/b> variable is subtracted from the total number of seconds contained in the <b>$baseLine<\/b> variable. This number is then divided by the total number of seconds contained in the <b>$baseLine<\/b> variable. The result of this computation is then multiplied by 100. The <b>Get-Change<\/b> function is seen here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">Function Get-Change($baseLine, $modified)<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">{<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>(($baseLine &#8211; $modified)\/$baseLine)*100<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">} #end Get-Change function<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">After the <b>Get-Change<\/b> function is created, the <b>Get-TempFile<\/b> function is created. The <b>Get-TempFile<\/b> function calls the static <b>GetTempFileName<\/b> method from the <b>Io.Path<\/b> .NET Framework class. The <b>Get-TempFile<\/b> function is seen here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">Function Get-TempFile<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">{<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>[io.path]::GetTempFileName()<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">} #end Get-TempFile function<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">After all the functions have been created, you arrive at the entry point to the script. The first thing to do is to see if the Test-TwoScripts.ps1 script was run with the <b>&ndash;log<\/b> switched parameter. If it was launched with the <b>&ndash;log<\/b> switched parameter, the <b>$log<\/b> variable will exist. And if the <b>$log<\/b> variable exists, the <b>Get-TempFile<\/b> function is called and the resulting temporary file name is stored in the <b>$logFile<\/b> variable. This is seen here:<\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>if($log) { $logFile = Get-TempFile }<\/span><\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">A <b>for<\/b> loop is used to count the number of tests to perform on the scripts. The number of tests is stored in the <b>$numberOfTests<\/b> variable. A status message is displayed in the Windows PowerShell console that indicates the test loop number. This section of the code is seen here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">For($i = 0 ; $i -le $numberOfTests ; $i++)<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">{<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>&#8220;Test $i of $numberOfTests&#8221; ; start-sleep -m 50 ; cls<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">After the loop progress message is displayed, the <b>Test-Scripts<\/b> function is called. The <b>Test-Scripts<\/b> function returns two <b>System.TimeSpan<\/b> objects. These two objects are stored in the <b>$results<\/b> variable. This is seen here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span><span>$results= Test-Scripts -baseLineScript $baseLineScript -modifiedScript $modifedScript<\/span><\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">Because the <b>$results<\/b> variable contains an array of two <b>TimeSpan<\/b> objects, you can index directly into the array and retrieve the value of the <b>TotalSeconds<\/b> variable. Use <b>[0]<\/b> to retrieve the first <b>TimeSpan<\/b> object and <b>[1]<\/b> to retrieve the second <b>TimeSpan<\/b> object. The total seconds from the current test run is added to the total seconds that are stored in the <b>$baseLine<\/b> and <b>$modified<\/b> variables. This is seen here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>$baseLine += $results[0].TotalSeconds<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>$modified += $results[1].TotalSeconds<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">If the script is run with the <b>&ndash;log<\/b> switched parameter, the name of the script, the test number, and the results are written to the log file. The code that does this is seen here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>If($log)<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>{<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8220;$baseLineScript run $i of $numberOfTests $(get-date)&#8221; &gt;&gt; $logFile<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$results[0] &gt;&gt; $logFile<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8220;$modifiedScript run $i of $numberOfTests $(get-date)&#8221; &gt;&gt; $logFile<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$results[1] &gt;&gt; $logFile<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp; <\/span>} #if $log<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">} #for $i <\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">After writing to the log file, it is time to display information to the Windows PowerShell console. The number of tests and the average time for each test run is displayed in the console for both the baseline and the modified scripts. The portion of the script that performs this action is shown here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">&#8220;Average change over $numberOfTests tests&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">&#8220;BaseLine: $baseLineScript average Total Seconds: $($baseLine\/$numberOfTests)&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">&#8220;Modified: $modifiedScript average Total Seconds: $($modified\/$numberOfTests)&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The percentage of change between the two scripts is calculated by using the <b>Get-Change<\/b> function. The <b>{0:N2}<\/b> format specifier indicates the percentage change to two decimal places. This is seen here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&#8220;Percent Change: &#8221; + &#8220;{0:N2}&#8221; -f (Get-Change -baseLine $baseLine -modified $modified)<\/span><\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The same information that was just displayed to the console is written to the log file if the script is launched with the <b>&ndash;log<\/b> switched parameter. This section of the script is shown here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">if($log)<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">{<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>&#8220;Average change over $numberOfTests tests&#8221; &gt;&gt; $logFile<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>&#8220;BaseLine: $baseLineScript average Total Seconds: $($baseLine\/$numberOfTests)&#8221; &gt;&gt; $logFile<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>&#8220;Modified: $modifiedScript average Total Seconds: $($modified\/$numberOfTests)&#8221; &gt;&gt; $logFile<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>&nbsp;<\/span>&#8220;Percent Change: &#8221; + &#8220;{0:N2}&#8221; -f (Get-Change -baseLine $baseLine -modified $modified) &gt;&gt; $logFile<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">} #if $log<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">After the log file has been updated, it is displayed by using Notepad. The code that displays the log file in Notepad is seen here: <\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\"><span>if($log) { Notepad $logFile }<\/span><\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The log that is produced is seen here:<\/p>\n<p class=\"MsoNormal\"><span><img decoding=\"async\" title=\"Image of log produced\" alt=\"Image of log produced\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/july\/hey0723\/hsg-07-23-09-01.jpg\" width=\"600\" height=\"457\"><\/span><\/p>\n<p class=\"MsoNormal\"><br>Well, JH, we hope you found our helping hand useful. The performance testing of scripts after they have been modified is a good way to see if your changes are good ones. Join us tomorrow as we reach into the virtual mail bag for Quick-Hits Friday. <a href=\"https:\/\/twitter.com\/scriptingguys\/\">Follow us on Twitter<\/a> to stay up to date will all the latest news on the Script Center. You can also <a href=\"http:\/\/www.facebook.com\/group.php?gid=5901799452\">join our Facebook group<\/a> for similar purposes. Don&#8217;t forget about the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/a> where thousands of dedicated scripters from all over the world meet to discuss scripts. Drop us an e-mail at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><span>scripter@microsoft.com<\/span><\/a> to let us know how things are going. Until tomorrow, have a great day!<\/p>\n<p class=\"MsoNormal\"><b><span><br><\/span><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/span><\/b><\/p>\n<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Hey Scripting Guy! I have a script that I wrote, and I am interested in modifying it to try and make it run faster. I know I can use the Measure-Object Windows PowerShell cmdlet, but I want to run the script several times and get the average time it takes for each script to [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2,3,4,45],"class_list":["post-52883","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-running","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Hey Scripting Guy! I have a script that I wrote, and I am interested in modifying it to try and make it run faster. I know I can use the Measure-Object Windows PowerShell cmdlet, but I want to run the script several times and get the average time it takes for each script to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52883","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=52883"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52883\/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=52883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=52883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=52883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}