2012-06-18 24 views
-2

我試圖獲取具有繁重的I/O讀取以及關聯的ProductVersion的進程的列表。該守則將是這個樣子:Powershell使用進程信息檢索每個進程的IO操作並列出

$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 

回答

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 
+0

我意識到我可以使用Format-Table來顯示輸出;然而這裏的訣竅是我需要獲得計數器和處理信息。如果我只需要櫃檯,那麼你的答案是正確的;但是,我沒有。謝謝,不過。 –

+0

如果您看到第一列,它包含進程信息 –

+0

我正在查找的進程信息是ProductVersion。請完整閱讀該問題。 –

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 
相關問題