磁盘的计数器表格格式

时间:2013-10-19 18:08:27

标签: powershell formatting performancecounter powershell-v3.0

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

如何设置' Get-counter'的输出格式?像这样的命令。

enter image description here

1 个答案:

答案 0 :(得分:2)

$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