Getting network interface device name in powershell

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.


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.


When attempting the answer from Grant I got some errors indicating I was attempting to print a null variable. Here is the workaround:

$interfaces = Get-WmiObject Win32_NetworkAdapter
$interfaces | ForEach{
    $friendlyname = $_ | ForEach-Object { $_.NetConnectionID }
    $name = $_.GetRelated("Win32_PnPEntity") | Select-Object -ExpandProperty Name
    # This tests to ensure friendlyname isn't null
    if($friendlyname){
        "$friendlyname is $name"
    }
}

Here is a way to list only PHYSICAL device names:

$query = "SELECT * FROM Win32_NetworkAdapter WHERE Manufacturer != 'Microsoft' AND NOT PNPDeviceID LIKE 'ROOT\\%'"
$interfaces = Get-WmiObject -Query $query | Sort index
$interfaces | ForEach{
    $friendlyname = $_ | ForEach-Object { $_.NetConnectionID }
    $name = $_.GetRelated("Win32_PnPEntity") | Select-Object -ExpandProperty Name
    # This tests to ensure friendlyname isn't null
    if($friendlyname){
        "$friendlyname is $name"
    }
}

Output:

Ethernet is Intel(R) Ethernet Connection (6) Is19-LM
Wi-Fi is Intel(R) Wi-Fi 6 X200 160MHz