Powershell中的性能计数器API调用错误
我想通过Powershell从Perfmon获取有关性能的特定信息,并使用另一个服务运行的脚本将其写入.csv文件。我知道Powershell会给出一些有趣的错误消息,所以我想听听你们是否能告诉我我到底做错了什么 我试图使代码生效的代码如下所示:Powershell中的性能计数器API调用错误,powershell,counter,performance-monitor,Powershell,Counter,Performance Monitor,我想通过Powershell从Perfmon获取有关性能的特定信息,并使用另一个服务运行的脚本将其写入.csv文件。我知道Powershell会给出一些有趣的错误消息,所以我想听听你们是否能告诉我我到底做错了什么 我试图使代码生效的代码如下所示: $date = (Get-Date).ToShortDateString() Get-Counter $gc = @("\Memory\% Committed Bytes In Use", "\Memory\Availa
$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 = @("\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
以下是有效的代码:
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
我不得不避开
*
符号,但这并不是我问题的一部分,这样做时,我没有在.csv中显示网络接口样本。它显示在PS控制台中,但随后不在.csv中。对此不确定,请将其作为单独的问题与示例一起发布