Question:
I can get the network card counter instance names like so:
1 2 |
Get-WmiObject Win32_PerfRawData_Tcpip_NetworkInterface |
Which outputs something like this for Name:
1 2 3 4 5 |
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:
1 2 |
Get-WmiObject win32_networkadapter -filter "netconnectionstatus=2" |
which outputs something like this for Name:
1 2 3 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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.
Answer:
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:
1 2 3 |
$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 :
1 2 |
Intel_R__Ethernet_Controller_X540_AT2__4 |