Performance Counters – 2012 PowerShell Scripting Games Beginner Event #10

Gather all of the counter information for the processor counter set. Take three separate readings at five second intervals. This information should be appended to a single text file named servername_ProcessorCounters.txt in the Documents special folder. You'll lose points for complexity. Use native PowerShell commands where possible.

This was the most confusing event for me since it specified "Processor Performance Counter Set" in one of the design points and my home pc with an AMD processor has a "Processor Performance" counter set:

2012sg-be10-1.png

Comparing the results of what the "Processor Performance" counter set returned on my pc to the screenshot provided in the scenario requirements assisted me in determining that what they were really asking for was the information in the "Processor" counter set.

2012sg-be10-11.png

I spent a lot of time trying to figure out how to sort my data as shown in the screenshot provided in the scenario requirements of this one. I happened to come across a Hey, Scripting Guy! Blog article on Use PowerShell to Simplify Collecting Performance Information that showed how to accomplish the proper sorting.

The second difficult part was figuring out what the Documents special folder was? I found another blog article titled The Easy Way to Use PowerShell to Work with Special Folders on the Hey, Scripting Guy! Blog that helped and then all I had to do was put the pieces together. I initially used "Combine" to combine the Documents special folder with the server name and file name but that didn't use native PowerShell commands. I also had to figure out that an escape character (the grave accent or back-tick) was needed after the $Env:ComputerName variable to use it as part of the file name as shown below:

2012sg-be10-2.png

While looking at other people's scripts for Beginner event #3, I found a reference to using Join-Path by one of the judges. I had used the same method as that person but didn't receive that sort of feedback so I was lucky I found this. Here's the script I submitted:

1Get-Counter -Counter (Get-Counter -ListSet Processor).Paths -SampleInterval 5 -MaxSamples 3 |
2Out-File -Append -FilePath (Join-Path -Path ([Environment]::GetFolderPath("MyDocuments")) -ChildPath "$Env:ComputerName`_ProcessorCounters.txt")

µ