0

我一直在尝试让 powershell 在 Windows 7 的 perfmon.exe 中制作一个包含某些信息的 csv 文件

大部分都有效,但似乎忽略了 3 个计数器。

该脚本如下所示:

$SampleInterval="4"
$MaxSamples="15"
$FileDestinationFolder="C:\Perfmon"
$date = (Get-Date).ToShortDateString()
Get-Counter 
$gc = ('\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',
        '\Memory\% Committed Bytes In Use',  
        '\Memory\Available MBytes')
Get-Counter -counter $gc -SampleInterval $SampleInterval -MaxSamples $MaxSamples | export-counter -force -path ("$FileDestinationFolder\PerfMon-$date.csv") -FileFormat csv

我确实获得了 PhysicalDisk、处理器和内存的统计信息,但没有获得网络接口的统计信息。网络接口的路径是从数据收集器本身获取的。任何线索为什么会这样?

编辑——如果我单独阅读它们,我可以看到它会打印 Powershell ISE 中的所有网络接口,但不会将内容写入 csv 文件。

输出示例是

Timestamp CounterSamples
--------- --------------
06-12-2012 15:13:30 \dkspare03\network interface(intel[r] 82577lm gigabi t network connection )\字节总数/秒:
27101,2080498825

                      \\dkspare03\network interface(intel[r] centrino[r] ad
                      vanced-n 6200 agn)\bytes total/sec :                 
                      0

目前,网络接口有一个转义字符,它告诉要读取什么 NIC。如果我没有它,powershell 会列出如下错误:

Get-Counter:内部性能计数器 API 调用失败。错误:c0000bb9。在 line:38 char:12 + Get-Counter <<<< -counter $gc -SampleInterval $SampleInterval -MaxSamples $M axSamples | export-counter -force -path ("$FileDestinationFolder\PerfMon-$date.csv") -FileFormat csv + CategoryInfo : InvalidResult: (:) [Get-Counter], Exception + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.Ge tCounterCommand

4

1 回答 1

1

计数器似乎需要 Powershell 3.0。编辑日期变量以避免在命名文件和文件夹时产生更多麻烦。此外,“已收到”必须更改为“已收到”。

于 2012-12-06T16:05:29.127 回答