I needed a powershell 2 script to get the name and device name of each interface like it is shown in network connections in control panel.
Should be easy...
$interfaces = Get-WmiObject Win32_NetworkAdapter
$interfaces | foreach {
$friendlyname = $_ | Select-Object -ExpandProperty NetConnectionID
$name = $_ | Select-Object -ExpandProperty Name
"$friendlyname is $name"
}
However, $name comes back as "Broadcom BCM5709C NetXtreme II GigE (NDIS VBD Client)", whereas in control panel it shows "Broadcom BCM5709C NetXtreme II GigE (NDIS VBD Client) #69", because there are multiple cards. I can't find that number anywhere in the properties.
How can I get both the Name and Device Name, exactly as shown in Network Connections, in powershell 2 on windows server 2008 r2?
Update: The really weird thing is it shows the # part for other kinds of network cards - the interfaces for teamed cards show it properly. My nvidia based ones show it on my desktop system. Maybe it's only the broadcom cards? The server in question is a Dell R715, with 4 onboard broadcom nics, and a 4 port broadcom addon card.
After testing on some more systems (and commenter's tests on their systems), it appears to be a "feature" of the broadcom drivers. Updating the drivers didn't change anything.
What ways are there, besides Get-WmiObject Win32_NetworkAdapter to get both the Name and Device Name of all the network adapters in a system?
Finally, found the solution! Since it does show up correctly in the registry and device manager, we can get it from the related Win32_PnPEntity object. So the code becomes:
This matches perfectly with the names in device manager and network connections on all of the systems I have tried it on.
I'm not sure if this is your whole code, but with your current loop, you are just writing over the
$friendlyname
and the$name
variables. It might be that the last item was the one without the number on it. The following code gave me the results you are looking for:You can then use
$outputs | out-grid
to see all that was listed on your system.When attempting the answer from Grant I got some errors indicating I was attempting to print a null variable. Here is the workaround:
Here is a way to list only PHYSICAL device names:
Output:
I use this on Windows10:
You can find more examples on Get-NetAdapter