2
我想通過Powershell從Perfmon獲取有關性能的特定信息,並使用由其他服務運行的腳本將其寫入.csv文件。我知道Powershell可以提供一些有趣的錯誤信息,因此我想聽聽是否有人可以約束我做錯了什麼。Powershell中的性能計數器API調用錯誤
我試圖使工作的代碼看起來是這樣的:
$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
然而,這是不是直接我的問題的一部分,我不以這種方式獲取.csv中顯示的網絡接口採樣。它在PS控制檯中顯示,但之後不在.csv中。 –
不確定,請將它作爲單獨的問題與示例一起發佈 –