7

I can get the network card counter instance names like so:

 Get-WmiObject Win32_PerfRawData_Tcpip_NetworkInterface

Which outputs something like this for Name:

Intel[R] Ethernet Controller X540-AT2
Intel[R] Ethernet Controller X540-AT2 _2
Intel[R] Ethernet Controller X540-AT2 _3
Intel[R] Ethernet Controller X540-AT2 _4

I can get the (enabled) Network cards like so:

Get-WmiObject win32_networkadapter -filter "netconnectionstatus=2"

which outputs something like this for Name:

Intel(R) Ethernet Controller X540-AT2
Intel(R) Ethernet Controller X540-AT2 #4

However there's no properties returned from either call that directly match the other.

The closest is win32_networkadapter's name, which is similar to the counter name, but has been altered to remove illegal characters and alter others(*1), and has some sort of instancing going on(*2).

(*1) = Just in testing, it swaps round brackets ("()") for the square brackets ("[]"), and escapes hashes for underscores.

(*2) = In a machine with four network adapters,

My question is: How do I directly map one for the other, without relying on my guesswork text replacement?

Edit:
If you're trying to test this on a VM, you'll need to add at least two network cards.

Here's the relevant output from a Windows Server 2012 R2 VM running on Hyper-V:

 Get-WmiObject Win32_PerfRawData_Tcpip_NetworkInterface | select Name

 Name
 ----
 Microsoft Hyper-V Network Adapter
 Microsoft Hyper-V Network Adapter _2
 Microsoft Hyper-V Network Adapter _3


 Get-WmiObject win32_networkadapter -filter "netconnectionstatus=2" | select Name

 Name
 ----
 Microsoft Hyper-V Network Adapter #2
 Microsoft Hyper-V Network Adapter
 Microsoft Hyper-V Network Adapter #3

Edit again:

String replacement is right out, and just doesn't work on servers that are using NIC teaming.

Here's an example of a server that's using NIC teaming:

 Get-WmiObject win32_networkadapter -filter "netconnectionstatus=2" | select name

 Name
 ----
 Intel(R) 82575EB Gigabit Network Connection
 Intel(R) 82575EB Gigabit Network Connection
 Intel(R) 82576 Gigabit Dual Port Network Connection
 Intel(R) 82576 Gigabit Dual Port Network Connection
 TEAM : PublicTeam
 TEAM : PrivateTeam


 Get-WmiObject Win32_PerfRawData_Tcpip_NetworkInterface | select Name


 Name
 ----
 TEAM : PrivateTeam - Intel[R] 82575EB Gigabit Network Connection
 TEAM : PublicTeam - Intel[R] 82575EB Gigabit Network Connection _2
 TEAM : PrivateTeam - Intel[R] 82576 Gigabit Dual Port Network Connection
 TEAM : PublicTeam - Intel[R] 82576 Gigabit Dual Port Network Connection _2

*Edit the third/fourth: *

Yet another machine that doesn't even use the above somewhat guessable naming scheme.

This is on Windows Server 2012 R2:

 Get-WmiObject Win32_PerfRawData_Tcpip_NetworkInterface | select Name

 Name
 ----
 Intel[R] 82576 Gigabit Dual Port Network Connection
 Intel[R] 82576 Gigabit Dual Port Network Connection _2
 Intel[R] 82576 Gigabit Dual Port Network Connection _3
 Intel[R] 82576 Gigabit Dual Port Network Connection _4

 Get-WmiObject win32_networkadapter -filter "netconnectionstatus=2" | select Name

 Name
 ----
 Intel(R) 82576 Gigabit Dual Port Network Connection
 Intel(R) 82576 Gigabit Dual Port Network Connection
 Microsoft Network Adapter Multiplexor Driver
 Microsoft Network Adapter Multiplexor Driver #2

Note that in this case, it's the Microsoft Network Adapter's that actually have IPs.

Although in this scenario, the matching performance counters on the adapter perf counters actually work (interface seems more reliable in other situations)

Edit 5:

People keep making comments like "It's similar to this other thread: Get Link Speed - Win32_PerfRawData_Tcpip_NetworkInterface"

As already explained in edits above, I give examples where this kind of text fudging doesn't work.

13
  • I dont think you can map Win32_PerfRawData_Tcpip_NetworkInterface to win32_networkadapter because there isnt a shared key..but you could relate to networkadapterconfiguration...it just depends on what properties of the nic you want to see....also which version of powershell are you using? Dec 3, 2015 at 7:01
  • I need the actual performance counter name - how I get there doesn't matter, so long as I can map it back to win32_networkadapter (or the win32_networkadapterconfiguration) - I'm using the information from that, to determine which perf counter relates to which network on the system (dmz, private, etc) - that perf counter instance name is then passed to another app. I don't see how the config table helps.
    – user111013
    Dec 3, 2015 at 10:43
  • Not sure what OS you are using but on my Windows 10 machine & a win 2012 virtual machine both classes return matching names so i am afraid i cannot test this.. Dec 4, 2015 at 2:05
  • @Kiran You will need multiple network cards of the same type. On a WS2012 R2 hyper-v guest I added three network cards and see as per the edit.
    – user111013
    Dec 4, 2015 at 4:36
  • Have you tried using Get-Counter and Get-NetAdapter instead ? Maybe you can match the interfaces easier then ? See (Get-Counter -ListSet "Network Adapter").PathsWithInstances for example for a list of network counters. WMI can be a pain sometimes ...
    – sodawillow
    Dec 5, 2015 at 11:28

1 Answer 1

0

I was not able to find the relation other than that name.

So as I can't imagine all the replacement caracters I instore a canonical name:

$cananicalName1 = "Intel(R) Ethernet Controller X540-AT2 #4" -replace '[^A-Za-z0-9]','_'
$cananicalName2 = "Intel[R] Ethernet Controller X540-AT2 _4" -replace '[^A-Za-z0-9]','_'

both gives :

Intel_R__Ethernet_Controller_X540_AT2__4
1
  • Unfortunately Text replacement doesn't help. I found a box where this won't work at all. I'll edit the question with more information.
    – user111013
    Dec 7, 2015 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy