It is a new year and the Chairman is preparing a fiendish new challenge for this year’s PowerShell + DevOps Summit. That time is rapidly. If you partook in last year’s battle then you understand what is expected of you. if you have not already done so align yourself with the faction that best suits you.
In order to prepare you for battle the Chairman has prepared a series of preparatory challenges. It is a foolish warrior who goes into battle unprepared. Just sayin’.
To prepare you for the upcoming battle, see what you can create according to the guiding principles of your faction that solves the following problem. The bottom line is that your solution should work.
The Get-Counter cmdlet is very useful in obtaining performance counter information. Unfortunately, the Chairman feels the output is less than friendly. Especially if you wish to consume the output such as with additional filtering, exporting to a json file or writing to a database.
Your challenge is to create a PowerShell function that takes the output from Get-Counter and transforms it into a more user friendly object. Each counter sample should be a separate object with these properties:
You are free to use whatever property names you want as long as it is clear what the values represent. A sample might look like this:
PS C:\> Get-Counter -computername server01 | MyFunction Datetime : 2/6/2019 1:34:30 PM Computername: SERVER01 Counterset : memory Counter : cache faults/sec Value : 0 Datetime : 2/6/2019 1:34:30 PM Computername: SERVER01 Counterset : physicaldisk(_total) Counter : % disk time Value : 5.63389896275325
If you want to really challenge yourself, define a custom type and format view that gives you a result like this:
PS C:\> get-counter -computername server01 | myfunction Timestamp: 2/6/2019 4:51:34 PM Computername Counterset Counter Value ------------ ---------- ------- ----- SERVER01 network interface(intel[r] ethernet connection  i219-lm) bytes total/sec 63.933330323139 SERVER01 processor(_total) % processor time 2.29286092227079 SERVER01 memory % committed bytes in use 58.2262708009747 SERVER01 memory cache faults/sec 9.98958286299047 SERVER01 physicaldisk(_total) % disk time 0.06629201377444 SERVER01 physicaldisk(_total) current disk queue length 0
All the information you need to know is included in this post. The Chairman will share a possible solution within the week. Good Luck and Good Scripting!