Hi,
Perfmon is one the favourites tools of all IT admins. Every IT admin love this tool and we love Powershell too.
As a Powershell users most of my time is spent on powershell tool and sometime there is a need arrive when you want to check few performance counters. and as you know i am quite lazy is doing stuffs and I think that laziness is a path to automation.
I don’t want to to pent RunBox and then type PerfMon and then click on OK and then add the performance counter which i needed.
In performance counters i don't care about Graphs , i do care about values.
Powershell give us a very nice and clean cmdlet to get the values of Performance counters. As i mentioned above I don’t care about the graph i do care about values and in powershell console every thing is Text and we love that texts.
To get the values of performance counter we need to use the cmdlet Get-Counter .
Lets Start.
To list all the performance counters sets use the command.
Get-Counter -ListSet *
This will show you the list and path of all Counter sets.
If you want to know what kind of Counter sets you do have in your system just piped the above command to the Select CounterSetName cmdlet
Get-Counter -ListSet * | select CounterSetName
we can also use wildcards in -ListSet parameter. I am looking for all disk related counter sets, to search all conter sets those have disk word in it i can use *Disk* argument in -ListSet parameter
Get-Counter -ListSet *disk*
I am interested in counter set Logical Disk. and i can piped the above command to show me the LogicalDisk counter set only using where-Object cmdlet.
Get-Counter -ListSet *disk* | where {$_.CounterSetName -eq "LogicalDisk" }
So now there is a little problem arise. if you want to see the detail list of counters and Paths, some how you can’t see the complete output. The whole output is truncated using … ,
We need a list of counter to use them ,the best workaround of the above problem is to save the above command in to a variable.
$DiskCounter = Get-Counter -ListSet *disk* | where {$_.CounterSetName -eq "LogicalDisk" }
we are saving the output of above command in to a $DiskCounter variable.
So now if you want to see the Logical Disk Performance counter paths we can use Dot Notation now.
$DiskCounter.Paths
if you want see the Logical Disk Counters only.
$DiskCounter.Counter
Of if you want to see the Logical Disk Performance Counter paths with instances with counters use.
$DiskCounter..PathsWithInstances
Okies Now.
I am interested in my C drive Disk Queue Length. and using $DiskCounter.PathsWithInstances i know that i have to use "\LogicalDisk(C:)\Avg. Disk Queue Length" counter.
Get-Counter -Counter "\LogicalDisk(C:)\Avg. Disk Queue Length" -SampleInterval 10
In above command we are using counter "\LogicalDisk(C:)\Avg. Disk Queue Length" to monitor the disk queue length of our C drive and using -SampleInterval parameter we are telling to get-Counter cmdlet to collect the data for 10 seconds.
if you want to see or monitor the counters you can use the -Continuous parameter.
Get-Counter -Counter "\LogicalDisk(C:)\Avg. Disk Queue Length" -Continuous
That’s all for now ,, and i think now have an idea how to use it
Thanks
Aman Dhally
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.