Question

Get-Counter '\PhysicalDisk(*)\% Idle Time', '\LogicalDisk(*)\Free Megabytes','\PhysicalDisk(*)\Avg. Disk sec/Read','\PhysicalDisk(*)\Avg. Disk Queue Length'|Select-Object -expandProperty countersamples|Select-Object -Property instancename, cookedvalue | ft -AutoSize

How can I format the output of the 'Get-counter' command like this.

enter image description here

Was it helpful?

Solution

$counters="\PhysicalDisk(*)\% Idle Time","\PhysicalDisk(*)\Avg. Disk sec/Read","\PhysicalDisk(*)\Avg. Disk Queue Length","\PhysicalDisk(*)\Avg. Disk sec/Write"
Get-Counter $counters |Select-Object -expandProperty CounterSamples | group InstanceName | foreach{
    $ht=New-Object System.Collections.Specialized.OrderedDictionary
    $ht.Add("Drive",$_.Name.ToUpper().Replace("_",""))
    foreach($item in $_.Group){
        $perfCName=$item.Path.Replace(("(" + $item.InstanceName + ")"),"").Split("\")[3,4] -join "\"
        $ht.Add($perfCName,$item.CookedValue)
    }
    New-Object PSObject -Property $ht
} | ft
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top