3

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

1 回答 1

2

这是有效的代码:

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

我不得不逃避*符号

于 2012-10-22T07:58:05.060 回答