Hi there,
if you need to quickly setup a perfmon, it is always fun to click it together. And its also fun to do this at scale š done this manually for 50 servers?… me neither!
Thats the reason why PowerShell is so awesome and should be used by everyone and for everything. š
Collect counters
First we need to get the counter names we want to capture. For this we can use the CmdLet “Get-Counter”
1 |
Get-Counter -ListSet processor* |
With this command we are searching for all counters with Processor* in their name. Just change the string and you can search for every counter you need.
To filter this a litte more we can get some information about the parent counters and if you need it a little bit more detailed counters also by each child counter
1 |
(Get-Counter -ListSet processor*).Paths |
Or
1 |
(Get-Counter -ListSet processor*).Counter |
…will get you a list of all parent counters
1 |
(Get-Counter -ListSet processor*).Pathswithinstances |
This one will give you a list of every single child counter in the set
This way you can select your counters and put them into an array. I will explain later how that will work.
Get your first counter information from a local machine
Now we can start collecting some information from these counters.
1 2 3 |
$counter = (Get-Counter -ListSet processor*).Paths Get-Counter -Counter $counter -SampleInterval 2 -MaxSamples 30 |
We simply add all counters into a variable and let out Get-Counter CmdLet do the rest..
Whoa…whoa.. stop right here. That does not really help, does it? This fast running list is not really better than anything done manually in perfmon.
But you could simply pipe that into something elseĀ and siff through it afterwards. Which would be also as fun and productive as doing all this manually in perfmon.
Simply use our other friend “Export-Counters” and pipe it into a .blg file and have it done that way.
1 2 3 |
$counter = (Get-Counter -ListSet processor*).Paths Get-Counter -Counter $counter -SampleInterval 5 -MaxSamples 10 | Export-Counter -Path C:\Temp\Processor.blg |
Now we can work with it. This command will run until the counterset has finished, in this case it will take 5*10= 50 secondsĀ (SampleIntervall * MaxSamples =Ā Runtime)
Output file (ignore the “old” folder…it’s old)
and the view in Perfmon
Remote
Now we’ve coverd the basics with this, we can move over to do this at scale. By using PowerShell remoting.Ā Ā There areĀ only three things to considerĀ if you want to do this remotly (apart from having PowerShell remotingĀ working in your environment)
- All counters you want to measure are neededĀ on the destination machine. Otherwise you willĀ get a bunch of errors that the counter cannot be found on the machine. Simply get the counters of the remote machine beforehand on that machine or machinetype.
- If you run the folowing command on multiple servers at once, the data will be combined into one single .BLG file for all servers. If you need seperate date just run it in an Invoke-Command scriptblock as a job.
- make sure you don’t use the same filename for the .blg file or use the -Force option to overwrite it. Otherwise you will end up with no data! I’ve had oneĀ or two ‘doh moments with this one…
1 |
$counter = (Get-Counter -ListSet processor*).Paths Get-Counter -ComputerName fredsc01 -Counter $counter -SampleInterval 5 -MaxSamples 10 | Export-Counter -Path C:\Temp\fredsc01_Processor.blg |
This command simply gets the counters from the remote VM “FreDSC01” and puts it into a new .blg file.
If you know which counters you want to collect you can put them into an array (as mentioned earlier).
1 2 3 4 5 6 7 8 9 10 11 |
$counter = @( 'Processor(*)\% Processor Time', 'PhysicalDisk(*)\Avg. Disk Queue Length', 'PhysicalDisk(*)\Avg. Disk Read Queue Length', 'PhysicalDisk(*)\Avg. Disk Write Queue Length', 'PhysicalDisk(*)\Disk Reads/sec', 'PhysicalDisk(*)\Disk Writes/sec', 'PhysicalDisk(*)\Disk Bytes/sec', 'PhysicalDisk(*)\Disk Read Bytes/sec', 'PhysicalDisk(*)\Disk Write Bytes/sec' ) |
This way you can choose your counterset and change it pretty easily.
If you need an inspiration which counters you need to go a little bit deeper with a little bit more automationĀ for the evaluation in the end. You can also take a look at PAL.
Cheers Philipp
Thanks for the write up! Very useful post!
Great article! Is there a way to do similar PowerShell scripts with Resource Monitor?
thanks, i guess you could also do something with WMI to get some performance data as well. but normally you can get all needed data with the PowerShell basics I wrote about, just put all needed counters together. But Resource Manager is just an “at a glance tool” to see whats going on.