Iron Scripter 2019 is Coming

Iron Scripter 2019 is Coming

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 Challenge

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:

  • Timestamp
  • Computername
  • CounterSet
  • Counter
  • Value

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:

Advanced Challenge

If you want to really challenge yourself, define a custom type and format view that gives you a result like this:

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!

Jeffery Hicks

9 thoughts on “Iron Scripter 2019 is Coming

IRON SCRIPTER 2019 BEGINS! | PowerShell.orgPosted on  10:33 pm - Feb 13, 2019

[…] to https://ironscripter.us/iron-scripter-2019-is-coming/ right […]

    Daniel EvansPosted on  3:11 am - Feb 14, 2019

    I took a shot at this and here’s what I came up with. The function allows you to specify -tableView $true or $false, and the results will display accordingly as specified by the challenge criteria. If you do not declare -tableView when calling the function, it will default to false and display the list.

    function Parse-CounterData($input, [bool]$tableView)
    {

    $objectArray = @()
    $functionData = $input.CounterSamples | Select Path, CookedValue, Timestamp
    $functionData | Foreach-Object {

    $varPath = $_.Path
    $pathObjects = $varPath.Split(‘\’)

    $object = New-Object -TypeName PSObject
    $object | Add-Member -MemberType NoteProperty -Name ComputerName -Value $pathObjects[2]
    $object | Add-Member -MemberType NoteProperty -Name CounterSet -Value $pathObjects[3]
    $object | Add-Member -MemberType NoteProperty -Name Counter -Value $pathObjects[4]
    $object | Add-Member -MemberType NoteProperty -Name Value -Value $_.CookedValue

    If ($tableView -ne $true)
    {
    Return $object
    }
    else
    {
    $objectArray += $object
    $timestamp = “Timestamp: ” + $_.Timestamp
    }
    }

    If ($tableView -eq $true)
    {

    Return $timestamp, $objectArray | Format-Table
    }

    }

    Get-Counter | Parse-CounterData -tableView $true

AdamPosted on  9:31 am - Feb 15, 2019

Working nice 🙂 We want more 🙂

My Noob Solution For Iron Scripter 2019 Intro Challenge – How to Code .NETPosted on  1:01 am - Feb 16, 2019

[…] Intro Challenge: https://ironscripter.us/iron-scripter-2019-is-coming/ […]

A Warm-Up Solution – Iron ScripterPosted on  3:22 pm - Feb 18, 2019

[…] prepare you for the upcoming battle you were offered a warm-up challenge. The basic challenge was to take the output from Get-Counter and pipe it through a command you […]

Rob HagmanPosted on  3:44 pm - Feb 19, 2019

Who needs a function

Get-Counter|foreach-object{
$Timestamp = $_ |Select-object -expandproperty Timestamp
$_.CounterSamples | Where-object {$_.path -match “\\\\(.*)\\(.*)\((.*)\)\\(.*)”} | foreach-object{
$_|Select-object @{l=’Timestamp’;e={$Timestamp}},
@{l=’Computername’;e={$matches[1]}},
@{l=’Counterset’;e={$matches[2]}},
@{l=’Instance’;e={$matches[3]}},
@{l=’Counter’;e={$matches[4]}},
@{l=’Value’;e={$_.CookedValue}}
}}|format-table

to simple for a function really

Radjin Sardjoe MissierPosted on  2:42 am - Mar 3, 2019

function MyFunction {
param(
[parameter(Mandatory, ValueFromPipeline)] [object] $InputObject
)

$InputObject.CounterSamples | ForEach-Object {
[void] ($_.Path -match ‘\\\\(?.+?)\\(?.+?)\\(?.+)’)
$_ | Select-Object -Property @{n=’Datetime’; e={$_.Timestamp}},
@{n=’Computername’; e={$matches.Computername}},
@{n=’Counterset’; e={$matches.Counterset}},
@{n=’Counter’; e={$matches.Counter}},
@{n=’Value’; e={$_.CookedValue}}
}
}

Leave a Reply to Daniel Evans Cancel reply

%d bloggers like this: