Powershell使用流程信息检索每个流程和列表的IO操作

时间:2012-06-18 19:36:33

标签: powershell performancecounter

我正在尝试获取具有大量I / O读取的进程列表以及相关的ProductVersion。代码看起来像这样:

$counter = "\Process*\IO Read Operations/sec"
get-counter | ? {$counter -gt 10} | gps | select name,productversion,reads

,输出看起来像这样:

Name    ProductVersion    Reads
-----   --------------    -----
p1      16.1.723.2342     15.98324
p2      12.3.234.1231     11.34323

2 个答案:

答案 0 :(得分:1)

我认为您可以使用Format-Table

我使用不同的计数器来获取系统上的结果。你可以抽出一个类比并相应地使用: -

$Proc = Get-counter "\Process(*)\% processor time"

$Proc.CounterSamples | where {$_.instanceName -ne "idle"} | where {$_.instanceName -ne "_total"} | Format-Table -auto

<强>输出: -

Path                                                                   InstanceName                          CookedValue
----                                                                   ------------                          -----------
\\angshuman\process(system)\% processor time                           system                           1.54907723252374
\\angshuman\process(smss)\% processor time                             smss                                            0
\\angshuman\process(csrss#1)\% processor time                          csrss                            1.54907723252374

答案 1 :(得分:0)

要从多个源创建自定义表,您需要创建一个数组,然后将每个变量作为新对象传递:

$counter = "\Process*\IO Read Operations/sec"
$processes = gps | select id | ForEach {$_.id}
$ccounter = get-counter -listset process | get-counter -maxsamples 1 | select -expandproperty countersamples | where {$_.path -like $counter -and $_cookedvalue -eq $processes} | select cookedvalue | ForEach {$_.cookedvalue}
function Get-CounterValue ($mypid) { Code Here.... }
function GetProductVersion ($mypid) { ...code here... }
function GetProcessName ($mypid) { ...code here... }

$myresults = @()
$x = foreach ($procc in $processes) {
 $thisname = GetProcessName $procc
 $thisprod = GetProductVersion $procc
 $thisread = GetCounterValue $procc
 $robj = New-Object System.Object
 $robj | Add-Member -type NoteProperty -name Name -value $thisname
 $robj | Add-Member -type NoteProperty -name ProductVersion -value $thisprod
 $robj | Add-Member -type NoteProperty -name Reads -value $thisread
 $myresults += $robj
}
$myresults | ft -auto