-2

我正在尝试获取具有大量 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
4

2 回答 2

1

我认为您可以使用格式表

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

$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
于 2012-06-18T21:26:11.713 回答
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
于 2012-06-20T19:29:25.223 回答