Performance Counters? There’s a script for that.

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) :

get-counter -Counter "\Network Interface(*)\Bytes Total/sec" -SampleInterval 1 -MaxSamples 10


The –SampleInterval is in seconds, and the –MaxSamples sets how many you want. The –Counter parameter is the object and counter you want to monitor. Don’t know what they are for your system? No problem:

get-counter -ListSet *


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):

get-counter -ComputerName COLLOSSUS -Counter "\Network Interface(*)\Bytes Total/sec" -SampleInterval 1 -MaxSamples 10


If your machine happens not to be named “COLLOSSUS”, just change that part J. And yes, you can use whatever counters you like, including SQL Server locks, blocks, etc. The full reference for get-counter is here:


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 heartburn during the operation of this script, see a physician.

Comments (9)
  1. johnw73 says:

    I believe that you need the remote registry service to be enabled on Windows 2008 & beyond to collect performance counters remotely.

  2. BuckWoody says:

    Correct – if you can’t check the counters using the graphical tools, this won’t work either. They make the same call.

    Thanks for reading!

  3. greenie says:

    Thank you for the Powershell tips. Not being an OOP person makes it difficult at times to wrap my head around it.

    May I please,please use your disclaimer!

  4. BuckWoody says:

    Glad I could help!  And feel free to use the disclaimer…

  5. says:

    Hi Buck,

    Continuing to enjoy the blog very much. Quick follow up question.  I’ve searched for this particular pain point several times and can’t seem to find the single version of the truth.  Often, as a Sql DBA, I need to ascertain the port # on which Sql is running on a particular server.  How can I accomplish that from my desktop to any of my Sql boxes in my enterprise?  I know it’s there somewhere, as we have access to the SMO, but where oh wise one?



  6. BuckWoody says:

    Interestingly, you don’t need to ask SQL Server at all. Just use the registry:

  7. says:

    Fantastic, thanks!  

  8. Bill says:

    So the reurn from this is more than just the counter value. How would I extract the actual counter value from the returned "\nycitdl8333network interface(intel[r] wireless wifi link 4965agn _2)bytes total/sec :9182"

    Being that the value can be any number of digits getting only the last # of chars doesnt work.

  9. qrk314 says:

    Thanks for the code-ee bits.  LOVE your disclaimer

Comments are closed.

Skip to main content