{"id":51293,"date":"2010-02-15T00:01:00","date_gmt":"2010-02-15T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/02\/15\/hey-scripting-guy-can-i-use-windows-powershell-2-0-for-performance-monitoring\/"},"modified":"2010-02-15T00:01:00","modified_gmt":"2010-02-15T00:01:00","slug":"hey-scripting-guy-can-i-use-windows-powershell-2-0-for-performance-monitoring","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-can-i-use-windows-powershell-2-0-for-performance-monitoring\/","title":{"rendered":"Hey, Scripting Guy! Can I Use Windows PowerShell 2.0 for Performance Monitoring?"},"content":{"rendered":"<p class=\"MsoNormal\"><a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a>&nbsp;<\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p><img decoding=\"async\" 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\"><\/p>\n<p class=\"MsoNormal\">Hey, Scripting Guy! I love using performance monitor. I was a big fan of it back in the Windows NT 4.0 days, and I have been using it ever since. It seems, however, that beginning with Windows Vista you people have messed it up. In trying to make it easier for a clueless individual to use, you have absolutely messed it up for the IT pros who know what they are doing. In fact, as it stands right now, I use a Windows Server 2003 server as my monitoring machine, and I connect to everything remotely. I capture my performance logs on that box, and do all of my analysis from that machine. I have it connected to a switch box on my desktop and it works pretty well. I do wish, however, that I could use Windows PowerShell to parse the log files. That would be cool. For now, I am content with using PerfMon to do this. <\/p>\n<p class=\"MsoNormal\">&#8212; GM<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" 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 GM, <\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here. The Scripting Wife&rsquo;s idea of convalescing down on the South Carolina coast in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Murrells_Inlet,_South_Carolina\">Murrells Inlet<\/a> has been a capital idea. I take my laptop to the shore, make a recliner out of the sand, and plop down with a thermos of hot tea and write. It is a most relaxing way to work. Unfortunately, the South Carolina parks commission has not yet installed wireless access points on the beach, so I am having to use Outlook 2010 in offline mode, which works just great. I synchronize it in the morning, and in the evening when I return to the condo, and all is well. <\/p>\n<p class=\"MsoNormal\">GM, I was reading your e-mail about performance monitor, as I was watching the waves, and the sea gulls as they frolic in the sand. Because I am seldom without either my laptop or my camera, I am able to share a part of my experience with you. Here is a picture I snapped while writing this article. As you can see, it is a lovely day, especially at a time when much of the southern United States is still snowed in. I am sharing the beach with only a few sea gulls. <\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of seagulls on beach at Murrells Inlet\" alt=\"Image of seagulls on beach at Murrells Inlet\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/february\/hey0217\/hsg-02-17-10-01.jpg\" width=\"600\" height=\"211\"><\/p>\n<p class=\"Fig-Graphic\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">GM, I am not completely certain I understand what you are talking about when you say we ruined the performance monitor utility. For creating real-time graphs, it still works exactly the same way: Open PerfMon, add counters, and then look at the graph. An example graph is seen in the following image.<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of graph generated by PerfMon\" alt=\"Image of graph generated by PerfMon\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/february\/hey0217\/hsg-02-17-10-02.jpg\" width=\"600\" height=\"418\"><\/p>\n<p class=\"Fig-Graphic\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">However, if you are talking about creating logs, and copying counter sets and the like, I will agree that the process is a bit more convoluted. On the other hand, for experts such as yourself, you really need to learn how to use the counter cmdlets that have been added to Windows PowerShell 2.0. <\/p>\n<p class=\"MsoNormal\">One of the things I really love about Windows PowerShell is that I can use Windows PowerShell to help me learn how to use Windows PowerShell. (Did I just blow your mind?) For example, I can use the <b>Get-Command<\/b> cmdlet to find Windows PowerShell cmdlets that are related to performance counters:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-Command -Noun *counter*<\/p>\n<p>CommandType<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Definition<br \/>&#8212;&#8212;&#8212;&#8211;<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>&#8212;&#8212;&#8212;-<br \/>Cmdlet<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Export-Counter<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Export-Counter [-Path] &lt;String&gt; [-FileFormat &lt;St&#8230;<br \/>Cmdlet<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Get-Counter<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Get-Counter [[-Counter] &lt;String[]&gt;] [-SampleInte&#8230;<br \/>Cmdlet<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Import-Counter<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Import-Counter [-Path] &lt;String[]&gt; [-StartTime &lt;D&#8230;<\/p>\n<p>PS C:&gt;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">As seen here, there are three Windows PowerShell cmdlets that can be used to work with performance counters. Let&rsquo;s take some time to explore the <b>Get-Counter<\/b> cmdlet. The first thing to do is to use the <b>listset<\/b> parameter to retrieve information about performance counter sets. You can use wildcard characters to pull information about multiple performance counter sets, as\nshown in the following image.<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of using wildcard character to pull information about multiple performance counters\" alt=\"Image of using wildcard character to pull information about multiple performance counters\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/february\/hey0217\/hsg-02-17-10-03.jpg\" width=\"600\" height=\"414\"><\/p>\n<p class=\"MsoNormal\">After you have an idea of the counter set in which you are interested, you may wish to shift your focus to that particular counter set. This is shown here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-Counter -ListSet &#8216;processor information&#8217;<\/p>\n<p>CounterSetName<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Processor Information<br \/>MachineName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: .<br \/>CounterSetType<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: MultiInstance<br \/>Description<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: The Processor Information performance counter set consists of counters that measure aspects of processor activity. The processor is the part of the computer that performs arithmetic and logical computations, initiates operations on peripherals, and runs the threads of processes. A computer can have multiple processors. The Processor Information counter set represents each processor as an instance of the counter set.<br \/>Paths<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: {Processor Information(*)Processor State Flags, Processor Information(*)% of Maximum<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Frequency, Processor Information(*)Processor Frequency, Processor Information(*)Parking Status&#8230;}<br \/>PathsWithInstances :{Processor Information(_Total)Processor State Flags, Processor Information(0,_Total)Processor State Flags, Processor Information(0,3)Processor State Flags, Processor Information(0,2)Processor State Flags&#8230;}<br \/>Counter<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: {Processor Information(*)Processor State Flags, Processor Information(*)% of Maximum Frequency, Processor Information(*)Processor Frequency, Processor Information(*)Parking Status&#8230;}<\/p>\n<p>PS C:&gt;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The <b>Get-Counter<\/b> cmdlet returns a <b>CounterSet<\/b> object. This is seen here when we pipe the object to the Get-Member cmdlet. <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-Counter -ListSet &#8216;processor information&#8217; | Get-Member<\/p>\n<p><span>&nbsp;&nbsp; <\/span>TypeName: Microsoft.PowerShell.Commands.GetCounter.CounterSet<\/p>\n<p>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>MemberType<span>&nbsp;&nbsp;&nbsp; <\/span>Definition<br \/>&#8212;-<span>&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>&#8212;&#8212;&#8212;-<span>&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;-<br \/>Counter<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>AliasProperty Counter = Paths<br \/>Equals<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>bool Equals(System.Object obj)<br \/>GetHashCode<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>int GetHashCode()<br \/>GetType<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>type GetType()<br \/>ToString<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string ToString()<br \/>CounterSetName<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String CounterSetName {get;}<br \/>CounterSetType<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Diagnostics.PerformanceCounterCategoryType CounterSetType {get;}<br \/>Description<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String Description {get;}<br \/>MachineName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String MachineName {get;}<br \/>Paths<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Collections.Specialized.StringCollection Paths {get;}<br \/>PathsWithInstances Property<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Collections.Specialized.StringCollection PathsWithInstances {get;}<\/p>\n<p>PS C:&gt;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">We can therefore use dotted notation to retrieve the paths from the <b>CounterSet<\/b> object. This is seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; (Get-Counter -ListSet &#8216;processor information&#8217;).paths<br \/>Processor Information(*)Processor State Flags<br \/>Processor Information(*)% of Maximum Frequency<br \/>Processor Information(*)Processor Frequency<br \/>Processor Information(*)Parking Status<br \/>Processor Information(*)% Priority Time<br \/>Processor Information(*)C3 Transitions\/sec<br \/>Processor Information(*)C2 Transitions\/sec<br \/>Processor Information(*)C1 Transitions\/sec<br \/>Processor Information(*)% C3 Time<br \/>Processor Information(*)% C2 Time<br \/>Processor Information(*)% C1 Time<br \/>Processor Information(*)% Idle Time<br \/>Processor Information(*)DPC Rate<br \/>Processor Information(*)DPCs Queued\/sec<br \/>Processor Information(*)% Interrupt Time<br \/>Processor Information(*)% DPC Time<br \/>Processor Information(*)Interrupts\/sec<br \/>Processor Information(*)% Privileged Time<br \/>Processor Information(*)% User Time<br \/>Processor Information(*)% Processor Time<br \/>PS C:&gt;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">Because the <b>path<\/b> property returns a specific performance counter, such as <b>Processor Information(*)Processor State Flags<\/b>, you can pipe the results of the previous command to the <b>Get-Counter<\/b> cmdlet again, and return performance information from each of the performance counters. This is shown in the following image.<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of returning performance inform\nation for each performance counter\" alt=\"Image of returning performance information for each performance counter\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/february\/hey0217\/hsg-02-17-10-04.jpg\" width=\"600\" height=\"413\"><\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">GM, we will stop here. This should give you some ideas for playing around with the performance counter cmdlets in Windows PowerShell 2.0.<\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post your questionson the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/p>\n<p><\/span><\/b><\/p>\n<p><p>&nbsp;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; Hey, Scripting Guy! I love using performance monitor. I was a big fan of it back in the Windows NT 4.0 days, and I have been using it ever since. It seems, however, that beginning with Windows Vista you people have messed it up. In trying to make it easier for a clueless [&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":[51,41,31,3,45],"class_list":["post-51293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-monitoring","tag-operating-system","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; &nbsp; Hey, Scripting Guy! I love using performance monitor. I was a big fan of it back in the Windows NT 4.0 days, and I have been using it ever since. It seems, however, that beginning with Windows Vista you people have messed it up. In trying to make it easier for a clueless [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51293","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=51293"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51293\/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=51293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=51293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=51293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}