Perfmon.exe没有通过powershell显示网络接口的值

时间:2012-12-06 13:46:49

标签: powershell collections perfmon

我一直试图让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,处理器和内存的统计信息,但没有网络接口。网络接口的路径是从Data Collector本身获取的。 有任何线索可能会这样吗?

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

输出示例

  

时间戳CounterSamples
  --------- --------------
  06-12-2012 15:13:30 \ dkspare03 \ network interface(intel [r] 82577lm gigabi                             t网络连接)\字节总数/秒:
                            27101,2080498825

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

目前,网络接口有一个转义字符,用于说明要读取的NIC。 如果我没有它,powershell会出现如下错误:

  

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

1 个答案:

答案 0 :(得分:1)

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

相关问题