<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'PowerShell' and 'Performance Tuning'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=PowerShell,Performance+Tuning&amp;orTags=0</link><description>Search results matching tags 'PowerShell' and 'Performance Tuning'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>PowerShell Version Two – Get Continuous Perf Counters</title><link>http://sqlblog.com/blogs/buck_woody/archive/2010/02/25/powershell-version-two-get-continuous-perf-counters.aspx</link><pubDate>Thu, 25 Feb 2010 14:32:52 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:22620</guid><dc:creator>BuckWoody</dc:creator><description>&lt;p&gt;In version 2.0 of PowerShell, you can now use a direct command-let (get-Counter) to get at the Performance Monitor counters. For instance, to show the current value of the Processor Percent Time, use this command:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;span style="color:blue;"&gt;Get-Counter&lt;/span&gt; &lt;span style="color:darkred;"&gt;'\Processor(*)\% Processor Time'&lt;/span&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;The interesting part of get-Counter is that you can add a parameter at the end to keep sampling:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;span style="color:blue;"&gt;Get-Counter&lt;/span&gt; &lt;span style="color:darkred;"&gt;'\Processor(*)\% Processor Time' - Continuous&lt;/span&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;Which is very useful if you’re doing performance troubleshooting like I am this morning. And yes, you can use this to get at SQL Server counters as well – to see the entire set of counters, use this command:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;span style="color:blue;"&gt;Get-Counter&lt;/span&gt; &lt;span style="color:navy;"&gt;–listSet&lt;/span&gt; &lt;span style="color:blueviolet;"&gt;*&lt;/span&gt; &lt;span style="color:darkgray;"&gt;|&lt;/span&gt; &lt;span style="color:blue;"&gt;Select-Object&lt;/span&gt; &lt;span style="color:navy;"&gt;-ExpandProperty&lt;/span&gt; &lt;span style="color:blueviolet;"&gt;Paths&lt;/span&gt;&lt;span style="mso-spacerun:yes;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;    &lt;br /&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class="MsoNormal"&gt;&lt;font face="Calibri"&gt;&lt;b&gt;&lt;i style="mso-bidi-font-style:normal;"&gt;&lt;span style="color:maroon;font-size:10pt;mso-bidi-font-size:11.0pt;mso-bidi-font-family:calibri;mso-ansi-language:en;"&gt;Script Disclaimer, for people who need to be told this sort of thing: &lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i style="mso-bidi-font-style:normal;"&gt;&lt;span style="color:maroon;font-size:10pt;mso-bidi-font-family:calibri;mso-ansi-language:en;"&gt;           &lt;p&gt;&lt;/p&gt;         &lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;i style="mso-bidi-font-style:normal;"&gt;&lt;span style="color:maroon;font-size:10pt;mso-bidi-font-family:calibri;mso-ansi-language:en;"&gt;&lt;font face="Calibri"&gt;Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately.&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;</description></item><item><title>Performance Counters? There’s a script for that.</title><link>http://sqlblog.com/blogs/buck_woody/archive/2010/01/05/performance-counters-there-s-a-script-for-that.aspx</link><pubDate>Tue, 05 Jan 2010 14:02:15 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:20555</guid><dc:creator>BuckWoody</dc:creator><description>&lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font face="Calibri"&gt;&lt;font color="#000000"&gt;&lt;font size="3"&gt;It’s not hard to get Performance Monitor counters in PowerShell 1.0, and it’s REALLY easy in 2.0. This is one I used yesterday to monitor network bytes in and out on 2.0 (keep all of the green lines in this post on the same line) :         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="2"&gt;&lt;font face="Calibri"&gt;&lt;font color="#008000"&gt;get-counter -Counter &amp;quot;\Network Interface(*)\Bytes Total/sec&amp;quot; -SampleInterval 1 -MaxSamples 10         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;   &lt;p&gt;&lt;font color="#000000" size="3" face="Calibri"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font face="Calibri"&gt;&lt;font color="#000000"&gt;&lt;font size="3"&gt;The &lt;i style="mso-bidi-font-style:normal;"&gt;–SampleInterval&lt;/i&gt; is in seconds, and the &lt;i style="mso-bidi-font-style:normal;"&gt;–MaxSamples&lt;/i&gt; sets how many you want. The &lt;i style="mso-bidi-font-style:normal;"&gt;–Counter&lt;/i&gt; parameter is the object and counter you want to monitor. Don’t know what they are for your system? No problem:           &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="2"&gt;&lt;font face="Calibri"&gt;&lt;font color="#008000"&gt;get-counter -ListSet *         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;   &lt;p&gt;&lt;font color="#000000" size="3" face="Calibri"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font face="Calibri"&gt;&lt;font color="#000000"&gt;&lt;font size="3"&gt;Need to hit another computer? Easy Peasy – doesn’t even require remoting to be turned on (but you do need to have the rights to hit the perf counters):         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="2"&gt;&lt;font face="Calibri"&gt;&lt;font color="#008000"&gt;get-counter -ComputerName COLLOSSUS -Counter &amp;quot;\Network Interface(*)\Bytes Total/sec&amp;quot; -SampleInterval 1 -MaxSamples 10         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;   &lt;p&gt;&lt;font color="#000000" size="3" face="Calibri"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font color="#000000"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;If your machine happens not to be named “COLLOSSUS”, just change that part &lt;/font&gt;&lt;span style="font-family:wingdings;mso-ascii-font-family:calibri;mso-hansi-font-family:calibri;mso-char-type:symbol;mso-symbol-font-family:wingdings;"&gt;&lt;span style="mso-char-type:symbol;mso-symbol-font-family:wingdings;"&gt;J&lt;/span&gt;&lt;/span&gt;&lt;font face="Calibri"&gt;. And yes, you can use whatever counters you like, including SQL Server locks, blocks, etc. The full reference for get-counter is here: &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;a href="http://technet.microsoft.com/en-us/library/dd367892.aspx"&gt;&lt;u&gt;&lt;font color="#0000ff" size="3" face="Times New Roman"&gt;http://technet.microsoft.com/en-us/library/dd367892.aspx&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;    &lt;p&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;i style="mso-bidi-font-style:normal;"&gt;&lt;font size="2"&gt;&lt;font face="Calibri"&gt;&lt;font color="#800000"&gt;&lt;strong&gt;Script Disclaimer, for people who need to be told this sort of thing:             &lt;p&gt;&lt;/p&gt;           &lt;/strong&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;i style="mso-bidi-font-style:normal;"&gt;&lt;font size="2"&gt;&lt;font face="Calibri"&gt;&lt;font color="#800000"&gt;Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or heartburn during the operation of this script, see a physician.            &lt;p&gt;&lt;/p&gt;         &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/p&gt;</description></item><item><title>Measure Statement Performance with PowerShell</title><link>http://sqlblog.com/blogs/buck_woody/archive/2009/12/30/measure-statement-performance-with-powershell.aspx</link><pubDate>Wed, 30 Dec 2009 14:31:37 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:20376</guid><dc:creator>BuckWoody</dc:creator><description>&lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font color="#000000"&gt;&lt;font face="Calibri"&gt;When you monitor for performance, you might start in the database server itself. But a true test really has more to do with the “round trip” of a data request from a client to a server and then the return of data back to the client. &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font color="#000000"&gt;&lt;font face="Calibri"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font color="#000000"&gt;&lt;font size="3" face="Calibri"&gt;So I wired up this little test to simulate that process, and now I can run that from anywhere. The trick is the &lt;font color="#008000"&gt;measure-Command { }&lt;/font&gt; part, which brings back the time display. In my example, I’m testing the backup process, but your command can be anything you like. I’m also using the &lt;font color="#008000"&gt;ExecuteNonQuery&lt;/font&gt;&amp;#160; call, since I don’t want any data back. You might want to use the &lt;font color="#008000"&gt;ExecuteReader&lt;/font&gt; call if you do want data.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;   &lt;p&gt;&lt;font color="#000000" size="3" face="Calibri"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font color="#000000"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;If you want to try this (and remember, test system only, read and understand, etc.), you need to change the &lt;font color="#008000"&gt;SERVERNAME\INSTANCENAME&lt;/font&gt; to your system and instance names, and change the:          &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;font color="#008000"&gt;$sqlCommand.CommandText=&amp;quot;BACKUP DATABASE TESTDATABASE TO DISK='c:\TEMP\TESTDATABASE.bak' WITH INIT&amp;quot; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="3"&gt;&lt;font color="#000000"&gt;&lt;font face="Calibri"&gt;line to some command you want to run. &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font color="#000000"&gt;&lt;font face="Calibri"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font color="#000000"&gt;&lt;font face="Calibri"&gt;I’ve alternated the colors – keep all of one color on one line:         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;   &lt;p&gt;&lt;font color="#000000" size="3" face="Calibri"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt; &lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;font color="#008000"&gt;$sqlConnection = new-object System.Data.SqlClient.SqlConnection         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;font color="#800000"&gt;$sqlConnection.ConnectionString = &amp;quot;server=SERVERNAME\INSTANCENAME;integrated security=true;database=master&amp;quot;         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;font color="#008000"&gt;$sqlConnection.Open()         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;font color="#800000"&gt;$sqlCommand = new-object System.Data.SqlClient.SqlCommand         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;font color="#008000"&gt;$sqlCommand.CommandText=&amp;quot;BACKUP DATABASE TESTDATABASE TO DISK='c:\TEMP\TESTDATABASE.bak' WITH INIT&amp;quot;         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;font color="#800000"&gt;$sqlCommand.Connection=$sqlConnection         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;font color="#008000"&gt;Measure-command {$sqlCommand.ExecuteNonQuery()}         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="margin:0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;font color="#008000"&gt;$sqlConnection.Close()         &lt;p&gt;&lt;/p&gt;       &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;</description></item></channel></rss>