command to assign NIC name to a variable RRS feed

  • Question

  • I have a command where I will get the NIC adapter details in below format

    PS C:\> netsh interface ipv4 show interfaces
    Idx     Met         MTU          State                Name
    ---  ----------  ----------  ------------  ---------------------------
      1          50  4294967295  connected     Loopback Pseudo-Interface 1
     12           5        1500  connected     **Local Area Connection**

    And I am trying to get the NIC adapter name to a variable using below powershell command, but the problem here is command is getting executed, but no result it shows.

    $NIC = netsh interface ipv4 show interfaces

    $NICadapter = $NIC |? {$_.state -eq "connected"} | Select -ExpandProperty name

    Can anyone help me to correct this ?

    Note : I am using netsh, so that the command will work on all windows flavors.

    Friday, November 3, 2017 9:18 AM


  • netsh interface ipv4 show interface |where { $_ -match '\sconnected' -and $_ -notmatch 'loopback'}

    Get-WmiObject Win32_NetworkAdapter -Filter 'NetconnectionStatus=2'|select name,NetConnectionID


    • Marked as answer by Shimith Friday, November 3, 2017 11:04 AM
    Friday, November 3, 2017 9:38 AM