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'的输出格式?像这样的命令。
答案 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