How to get IP address, prefix (or netmask) and gateways for active interfaces in PowerShell?

30 views Asked by At

I'm trying to get the IP address, prefix (or netmask) and gateways for active interfaces in PowerShell.

I found these commands but cannot get all the information from the same command :

PS C:\> Get-NetIPConfiguration | ? { $_.NetAdapter.Status -ne "Disconnected" } | Select InterfaceAlias, IPv4Address , PrefixLength , IPv4DefaultGateway

InterfaceAlias IPv4Address   PrefixLength IPv4DefaultGateway
-------------- -----------   ------------ ------------------
LAN            {10.20.24.51}              {MSFT_NetRoute (InstanceID = ":8:8:8:9:55?@55;:8?:8??8;55;")}


PS C:\> Get-NetIPInterface -ConnectionState Connected -AddressFamily IPv4 | Get-NetIPAddress | Select  InterfaceAlias, IPv4Address , PrefixLength , IPv4DefaultGateway

InterfaceAlias              IPv4Address PrefixLength IPv4DefaultGateway
--------------              ----------- ------------ ------------------
LAN                         10.20.24.51           24
Loopback Pseudo-Interface 1 127.0.0.1              8



PS C:\>

I'm expecting this :

InterfaceAlias              IPv4Address   PrefixLength IPv4DefaultGateway
--------------              ---------   ------------ ------------------
LAN                         10.20.24.51           24 10.20.24.1
Loopback Pseudo-Interface 1 127.0.0.1              8 


PS C:\>
0

There are 0 answers