PowerShell - how to combine Get-NetAdapter with Get-NetIPAddress with Select-Object
Get-NetIPAddress doesn't show me the MacAddress of the adapters. So I want values from both of these commands in one table. So here is my solution using the power of Select-Object:
Get-NetAdapter |? Status -eq "Up" | SORT MacAddress | Select-Object @{n='Name';e={$_.NAME}},`
@{n='MacAddress';e={$_.MacAddress}},`
@{n='LinkSpeed';e={$_.LinkSpeed}},`
@{n='IPAddress';e={Get-NetIPAddress -InterfaceIndex $_.InterfaceIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty IPAddress}},`
@{n='PrefixLength';e={Get-NetIPAddress -InterfaceIndex $_.InterfaceIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty PrefixLength}}`
| ft -AutoSize
Here is my output:
You could save this into your powershell profile as a function if you wanted, or include it in your scripts after modifying network settings.
Labels: Powershell
