How to quickly create Perfmons with PowerShell

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”

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.

PerfMon_01

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

Or

PerfMon_02

will get you a list of all parent counters

This one will give you a list of every single child counter in the setPerfMon_02-2

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.

We simply add all counters into a variable and let out Get-Counter CmdLet do the rest..

PerfMon_03

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.

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)

PerfMon_04

and the view in Perfmon

PerfMon_06

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)

  1. 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.
  2. 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.
  3. 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…

This command simply gets the counters from the remote VM “FreDSC01” and puts it into a new .blg file.

 

PerfMon_08

If you know which counters you want to collect you can put them into an array (as mentioned earlier).

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

4 thoughts on “How to quickly create Perfmons with PowerShell

    1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *