Powershellを介してPerfmonからパフォーマンスに関する特定の情報を取得し、別のサービスによって実行されるスクリプトを使用して.csvファイルに書き込みたい。Powershellがいくつかの興味深いエラーメッセージを表示する可能性があることを知っているので、私が間違っていることを正確に識別できる人がいるかどうかを聞きたいと思います。
私が機能させようとしているコードは次のようになります。
$date = (Get-Date).ToShortDateString()
Get-Counter
$gc = @("\Memory\% Committed Bytes In Use",
"\Memory\Available MBytes",
"\Network Interface(*)\Current Bandwith",
"\Network Interface(*)\Packets Recieved/sec",
"\Network Interface(*)\Packets Sent/sec",
"PhysicalDisk(_Total)\Disk Write Bytes/sec",
"PhysicalDisk(_Total)\Disk Read Bytes/sec",
"Processor(_Total)\% Processor Time",
"Processor(_Total)\% Idle Time")
Get-Counter -counter $gc -SampleInterval 2 -MaxSamples 8 | export-counter -path C:\PerfMon2-$date.csv -FileFormat csv
次のようなエラーが発生します:
Get-Counter : Internal performance counter API call failed. Error: c0000bb9.
At C:\Users\jenstmar\Desktop\Nuværende Projekter\Perfmon.ps1:13 char:12
+ Get-Counter <<<< -counter $gc -SampleInterval 2 -MaxSamples 1 | export-counter -path C:\PerfMon2-$date.csv -FileFormat cs
v
+ CategoryInfo : InvalidResult: (:) [Get-Counter], Exception
+ FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand
それでも、詳細ではなくパフォーマンスカウンターのカテゴリを選択すると、機能します。例はこれです:
$date = (Get-Date).ToShortDateString()
Get-counter
$gc = (Get-Counter -listset "Network Interface").paths
$gc += (Get-Counter -listset "Processor").paths
$gc += (Get-Counter -ListSet "Processor Information").paths
$gc += (Get-Counter -listSet "memory").paths
$gc += (Get-Counter -listSet "PhysicalDisk").paths
get-counter -counter $gc -SampleInterval 2 -MaxSamples 8 | export-counter -path C:\PerfMon-$date.csv -FileFormat csv