【问题标题】:Performance Counter API call error in PowershellPowershell 中的性能计数器 API 调用错误
【发布时间】:2012-10-22 07:08:30
【问题描述】:

我想通过 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

【问题讨论】:

    标签: powershell counter performance-monitor


    【解决方案1】:

    这是有效的代码:

    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 中。
    • 不确定,将其作为单独的问题与示例一起发布
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    相关资源
    最近更新 更多