The way it works is pretty straightforward, but you need to know some background about Performance Counters if you haven't used them before. There are basically four pieces of information needed to retrieve a counter:
- Category
- Counter
- Instance
- Computer
If these don't ring a bell right away, fire up Perfmon, right-click and select Add Counters, and you'll see something like this:
In the top-left box you can see the Categories, and if you expand them you'll see the Counter names, and bottom left are the Instances.
Classic example: you want to find out the Current Disk Queue Length on your C: drive.
- Category = 'LogicalDisk'
- Counter = 'Current Disk Queue Length'
- Instance = 'C:'
- Computer = '.' (default, it means "this computer")
Using Get-PerformanceCounter, you'd do it like this:
Get-PerformanceCounter LogicalDisk 'C:' 'Current Disk Queue Length'
Or lets say you want to get all of the counters for the C: drive:
Get-PerformanceCounter LogicalDisk 'C:'
Anyway, here's the function, and you can also find it here: http://poshcode.org/2475
1 comment:
Great Work!
Post a Comment