Home > Net >  Enumerate all NICs with IP and MAC addresses in powershell
Enumerate all NICs with IP and MAC addresses in powershell

Time:11-23

How can I list all NICs with name, MAC and IP address in PowerShell?

I know that I can combine Get-NetIPAddress and Get-NetAdapter but is there a simple way to do it because it seems to be one of the most common things in network management.

I've also found that Get-NetIPConfiguration -Detailed, but I don't understand why Get-NetIPConfiguration -Detailed | select InterfaceAlias,NetAdapter.LinkLayerAddress,IPv4Address returns empty MAC addresses.

CodePudding user response:

The WMI class Win32_NetworkAdapterConfiguration contains this information:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computer localhost | Select Description, MACAddress, IPAddress

And more:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computer localhost | Select *

Using NetIPConfiguration -Detailed, you have to calculate the sub property LinkLayerAddress when using it in a select statement:

NetIPConfiguration -Detailed | 
    select InterfaceAlias, 
           IPv4Address, {$_.NetAdapter.LinkLayerAddress}

The above works, but we can give the calculated property a name, like this:

NetIPConfiguration -Detailed | 
select InterfaceAlias, 
       IPv4Address,
       @{
            name = 'MacAddress'
            expr = {$_.NetAdapter.LinkLayerAddress}
        }

Finally, as a one-liner:

NetIPConfiguration -Detailed | select InterfaceAlias, IPv4Address, @{name = 'MacAddress'; expr = {$_.NetAdapter.LinkLayerAddress}}
  • Related