Powershell: Counter Instance Name for specific Network Card

Question:

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

Which outputs something like this for Name:

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

which outputs something like this for Name:

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:

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:

*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:

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:

both gives :

Source:

Powershell: Counter Instance Name for specific Network Card by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply