Search code examples
powershellcollectionsperfmon

Perfmon.exe not showing values for Network Interface via powershell


I've been trying to make powershell make a csv file with certain information in Windows 7's perfmon.exe

Most of it works, but it seems to ignore 3 counters.

The script looks like the following:

$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

I do get stats for PhysicalDisk, Processor and Memory, but none of the Network Interfaces. The path for Network Interface is fetched from the Data Collector itself. Any clue why this may be so?

EDIT -- If I read them in alone, I can see that it prints all the network interfaces in the Powershell ISE, but doesn't write the content to the csv file.

Example on output is

Timestamp CounterSamples
--------- --------------
06-12-2012 15:13:30 \dkspare03\network interface(intel[r] 82577lm gigabi t network connection)\bytes total/sec :
27101,2080498825

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

Currently, Network Interface has an escape character where it tells what NIC to read. In case I do not have it, powershell enlist an error as following:

Get-Counter : Internal performance counter API call failed. Error: c0000bb9. At 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


Solution

  • The counter seemed to require Powershell 3.0. The date variable was edited to avoid creating further troubles in naming files and folders. Furthermore, "Recieved" had to be changed to "Received".