我不知道如何使用列表從系統記錄多個指標。 $CounterList
var不起作用,但$CounterList_Working
var起作用。我看到了一些基於路徑的列表,例如(Get-Counter -List Processor(*)).Paths
。如何一次返回多個性能計數器與Get-Counter?
我以爲我可以在一個變量指定的路徑,但不起作用。
什麼是錯的PowerShell腳本的$CounterList
?我得到的錯誤消息是「Get-Counter:在計算機上找不到指定的對象」。這讓我覺得它試圖把這個列表看作一個單一的值。
$CounterList = "\Network Interface(*)\Packets/sec
\Network Interface(*)\Current Bandwidth
\Network Interface(*)\Bytes Total/sec
\Memory\Committed Bytes
\Memory\Commit Limit"
$CounterList_Working = "\Processor(*)\% Processor Time"
echo "Gathering system data and writing to file $home\system_metrics.blg"
Get-Counter -Counter $CounterList -SampleInterval 2 -MaxSamples 10 | Export-counter -Path $home\system_metrics.blg
您的'$ CounterList'只是一個字符串,而不是一個字符串數組。與'$ arr ='str1','str2','str3''比較 - 有很多方法可以正確地聲明一個數組,你可能想看看。 – wOxxOm