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.
Win32_PerfRawData_Tcpip_NetworkInterface
towin32_networkadapter
because there isnt a shared key..but you could relate tonetworkadapterconfiguration
...it just depends on what properties of the nic you want to see....also which version of powershell are you using?win32_networkadapter
(or thewin32_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.Get-Counter
andGet-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 ...