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.

Community
  • 1
  • 1
  • 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? – Kiran Reddy Dec 03 '15 at 07: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. –  Dec 03 '15 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.. – Kiran Reddy Dec 04 '15 at 02: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. –  Dec 04 '15 at 04: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 05 '15 at 11:28
  • @sodawillow Those two don't really help much - same names are returned, and Get-Counter doesn't give any more useful information for matching one to the other. –  Dec 05 '15 at 22:58
  • Similar to this question: http://stackoverflow.com/questions/1832586/get-link-speed-win32-perfrawdata-tcpip-networkinterface – xXhRQ8sD2L7Z Dec 06 '15 at 23:35
  • @ST8Z6FR57ABE6A8RE9UF - only superficially - and they used string replacement (which, again, doesn't work in all scenarios) –  Dec 07 '15 at 00:12
  • Have you checked out the 'get-netadapter' and 'get-netadapterstatistics' cmdlets? https://technet.microsoft.com/en-us/library/jj130889(v=wps.630).aspx . I will say it's not perfect, but it's a lot more promising. The two cmdlets have the 'instanceid' and 'interfaceguid' which seem relatable, but my physical card doesn't have an entry in the 'get-netadapterstatistics'. I'll have to play around, but get-netadapter does at least indicate which NIC is physical and which is virtual (-HardwareInterface). – Jonathan H Dec 07 '15 at 17:13
  • The following thread discusses this issue: [http://stackoverflow.com/questions/1832586/get-link-speed-win32-perfrawdata-tcp ​ip-networkinterface](http://stackoverflow.com/questions/1832586/get-link-speed-win32-perfrawdata-tcp%E2%80%8C%E2%80%8Bip-networkinterface) – ConanW Dec 08 '15 at 21:50
  • @ConanW It does, as mentioned above. It's also using string replacement fudging, which doesn't work in all cases. –  Dec 09 '15 at 00:21
  • Possible duplicate of [Get Link Speed - Win32\_PerfRawData\_Tcpip\_NetworkInterface](http://stackoverflow.com/questions/1832586/get-link-speed-win32-perfrawdata-tcpip-networkinterface) – TravisEz13 Jan 09 '17 at 23:50
  • @TravisEz13 You're now the third person to mention this other thread. I've explained in existing edits why this isn't applicable. –  Jan 11 '17 at 04:58

1 Answers1

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
JPBlanc
  • 70,406
  • 17
  • 130
  • 175
  • 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. –  Dec 07 '15 at 00:00