1行

2016-07-29 3 views
3

に三つのコマンドからの出力を下げ、私はこのスクリプトを持っている:1行

$counterWS = "\Process(powershell)\Working Set" 
$counterWSPe = "\Process(powershell)\Working Set Peak" 
$counterWSPr = "\Process(powershell)\Working Set - Private" 

$dataWS = Get-Counter -Counter $counterWS 
$dataWSPe = Get-Counter -Counter $counterWSPe 
$dataWSPr = Get-Counter -Counter $counterWSPr 

$dataWS.countersamples | Format-Table Timestamp,@{Name='WorkingSet';Expression={($_.CookedValue/1KB)}},WorkingSetPeak,WorkingSetPrivate -Auto | findstr Timestamp 
$dataWS.countersamples | Format-Table Timestamp,@{Name='WorkingSet';Expression={($_.CookedValue/1KB)}},WorkingSetPeak,WorkingSetPrivate -Auto | findstr [-] 

while ($true) { 
    $dataWS.countersamples | Format-Table Timestamp,@{Name='WorkingSet';Expression={($_.CookedValue/1KB)}},WorkingSetPeak,WorkingSetPrivate -Auto | findstr [:] 
    $dataWSPe.countersamples | Format-Table Timestamp,WorkingSet,@{Name='WorkingSetPeak';Expression={($_.CookedValue/1KB)}},WorkingSetPrivate -Auto | findstr [:] 
    $dataWSPr.countersamples | Format-Table Timestamp,WorkingSet,WorkingSetPeak,@{Name='WorkingSetPrivate';Expression={($_.CookedValue/1KB)}} -Auto | findstr [:] 
    Start-Sleep -s $args[0] 
} 

をし、その結果は次のようである:

Timestamp   WorkingSet WorkingSetPeak WorkingSetPrivate 
---------   ---------- -------------- ----------------- 
29/07/2016 18:41:12  10644         
29/07/2016 18:41:13      10676     
29/07/2016 18:41:14          3056

あり、このような出力を行うために減らす方法を:

Timestamp   WorkingSet WorkingSetPeak WorkingSetPrivate 
---------   ---------- -------------- ----------------- 
29/07/2016 18:41:12  10644   10676    3056

答えて

4

3つのカウンタをまとめて収集します(パラメータ-Counterは引数のリストを受け入れます)。次に、結果をcalculated properties別個:

$ws  = '\Process(powershell)\Working Set' 
$wsPeak = '\Process(powershell)\Working Set Peak' 
$wsPriv = '\Process(powershell)\Working Set - Private' 

Get-Counter -Counter $ws, $wsPeak, $wsPriv | 
    Select-Object Timestamp, 
     @{n='WorkingSet';e={$_.CounterSamples[0].CookedValue/1KB}}, 
     @{n='WorkingSetPeak';e={$_.CounterSamples[1].CookedValue/1KB}}, 
     @{n='WorkingSetPrivate';e={$_.CounterSamples[2].CookedValue/1KB}} 

CounterSamplesプロパティは、インデックスによって個別にアクセスすることができるPerformanceCounterSampleオブジェクトのリストです。

Get-Counterに渡されたパラメータの順番で返される結果に頼りたくない場合は、そのパスで選択することができます。このように:連続サンプル採取のために

@{n='WorkingSetPeak';e={ 
    ($_.CounterSamples | Where-Object { $_.Path -like '*peak' }).CookedValue/1KB 
}} 

-Continuous-SampleIntervalGet-Counterにパラメータを追加します。ループは必要ありません。

$interval = 5 # seconds 

Get-Counter -Counter $ws, $wsPeak, $wsPriv -Continuous -SampleInterval $interval | 
    Select-Object ...