PowerShell Version Two – Get Continuous Perf Counters

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:

 Get-Counter '\Processor(*)\% Processor Time'   

The interesting part of get-Counter is that you can add a parameter at the end to keep sampling:

 Get-Counter '\Processor(*)\% Processor Time' - Continuous   

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:

 Get-Counter –listSet * | Select-Object -ExpandProperty Paths           

Script Disclaimer, for people who need to be told this sort of thing:

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.