I can get the network card counter instance names as follows:
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 network cards (included) as follows:
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
However, there are no properties returned from any call that directly matches the other.
The closest is the name win32_networkadapter, which is similar to the name of the counter, but has been changed to remove illegal characters and change others (* 1), and has some kind of action (* 2).
(* 1) = Just in testing, it collapses the brackets ("()") for the square brackets ("[]") and avoids the hashes to underline.
(* 2) = In a machine with four network adapters
My question is: how can I directly match one for the other without relying on my replacement of the text of the assumption?
Edit:
If you are trying to test this on a virtual machine, you need to add at least two network cards.
Here is the corresponding output of VM VM Windows Server 2012 R2 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
Change again:
Replacing strings directly and simply does not work on servers that use NIC networking.
Here is an example of a server using NIC aggregation:
Get-WmiObject win32_networkadapter -filter "netconnectionstatus=2" | select name Name
* Edit the third / fourth: *
Another machine that doesn't even use the aforementioned somewhat guessed 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
Please note that in this case, it is a Microsoft network adapter, which actually has IP addresses.
Although performance counters actually work on adapter cards in this scenario (the interface seems more reliable in other situations)
Change 5:
People keep making comments like "This is similar to this other topic: Get link speed - Win32_PerfRawData_Tcpip_NetworkInterface "
As already explained in the above editions, I gave examples when this type of fudging does not work.