1

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”命令的输出。

在此处输入图像描述

4

1 回答 1

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
于 2013-10-20T08:24:40.817 回答