Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Are you sure you aren't looking for the DeviceID? –  Zoredache Sep 13 '12 at 20:40
    
DeviceID isn't the right spot. However, I just checked, and double checked, and when I run this on my machines, the Name property is properly showing #2 at the end of the adapter name. Description shows it as just the adapter name. –  Steve G Sep 13 '12 at 20:51
    
The funny thing is that it does show the #x for SOME adapters...the virtual adapters for teaming show the numbers properly. But the actual broadcom interfaces don't. –  Grant Sep 14 '12 at 0:13
    
On the systems here it's exactly the opposite. Teamed adapters don't show the numbers, while standalone adapters do. You should be able to retrieve the complete names from the registry, though. Look in the subkeys of [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\EBDRV]. –  Ansgar Wiechers Sep 14 '12 at 11:57
    
Have you tried Win32_NetworkAdapterConfiguration –  Shawn Melton Sep 14 '12 at 17:00

2 Answers 2

up vote 2 down vote accepted

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:

$interfaces = Get-WmiObject Win32_NetworkAdapter
$interfaces | foreach {
    $friendlyname = $_ | Select-Object -ExpandProperty NetConnectionID
    $name = $_.GetRelated("Win32_PnPEntity") | Select-Object -ExpandProperty Name
    "$friendlyname is $name"
}

This matches perfectly with the names in device manager and network connections on all of the systems I have tried it on.

share|improve this answer

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:

$interfaces = Get-WmiObject Win32_NetworkAdapter
$Outputs = @()
foreach ($Interface in $Interfaces) { 
    $Output = New-Object -TypeName System.Object
    $Output | Add-Member -MemberType NoteProperty -Name FriendlyName -Value $Interface.NetConnectionID
    $Output | Add-Member -MemberType NoteProperty -Name Name -Value $Interface.Name
    $Outputs += $Output
}

You can then use $outputs | out-grid to see all that was listed on your system.

share|improve this answer
    
its not the whole code, just the broken bits. the loop actually does stuff with the variables. –  Grant Sep 14 '12 at 0:12
    
Ahh, I see. Then I'm not sure, because the Name field shows the number on my system. I'm testing on Windows 7 though, so it might have something to do with different OS's –  Nick Sep 14 '12 at 15:03
    
I'm actually thinking it's a driver issue. –  Grant Sep 14 '12 at 15:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.