PowerShell Get Network Adapter Info and IP Address

PowerShell Get Network Adapter Info and IP Address

PowerShell Tips Editor 3 min read
PowerShell Get Network Adapter Info and IP Address

Trying to script network configuration across 50 workstations with ipconfig means parsing text — fragile, slow, and painful. PowerShell get IP address queries using Get-NetIPAddress and Get-NetAdapter return real objects with filterable properties: interface name, IP, MAC, subnet mask, and status. You can filter to active adapters, query remote machines with CIM, and export a full inventory to CSV — all without touching a GUI or parsing a single string.

Get All IP Addresses

Get-NetIPAddress returns every IP address configured on every adapter — including loopback addresses and IPv6 link-local addresses. Pipe through Where-Object to narrow down to what you actually need.

# All IP addresses on local machine
Get-NetIPAddress
IPAddress         InterfaceAlias  AddressFamily  PrefixLength
---------         --------------  -------------  ------------
192.168.1.105     Ethernet        IPv4           24
127.0.0.1         Loopback        IPv4           8
::1               Loopback        IPv6           128
fe80::1           Ethernet        IPv6           64
# IPv4 only, exclude loopback
Get-NetIPAddress -AddressFamily IPv4 | Where-Object IPAddress -ne "127.0.0.1"

Filter to Active Adapters Only

Not every adapter is connected. Use Get-NetAdapter to find adapters in the Up state, then join the result to IP address data. This is the right approach when building inventory scripts where you only want production-facing adapters.

# Get adapters that are currently connected
$activeAdapters = Get-NetAdapter | Where-Object Status -eq "Up"

# Get IP addresses for those adapters only
foreach ($adapter in $activeAdapters) {
    Get-NetIPAddress -InterfaceIndex $adapter.InterfaceIndex -AddressFamily IPv4 |
        Select-Object InterfaceAlias, IPAddress, PrefixLength
}

Get MAC Address

MAC addresses are a property of the adapter, not the IP configuration. Use Get-NetAdapter and select the MacAddress property. The format uses dashes (00-1A-2B-3C-4D-5E) by default.

Get-NetAdapter | Select-Object Name, MacAddress, Status, LinkSpeed
Name       MacAddress          Status  LinkSpeed
----       ----------          ------  ---------
Ethernet   00-1A-2B-3C-4D-5E   Up      1 Gbps
Wi-Fi      A4-C3-F0-11-22-33   Disconnected  0 bps

Get Default Gateway

The default gateway is part of the route configuration, accessible via Get-NetRoute. Filter for the default route (destination prefix 0.0.0.0/0) to retrieve the gateway IP.

Get-NetRoute -DestinationPrefix "0.0.0.0/0" |
    Select-Object InterfaceAlias, NextHop, RouteMetric
InterfaceAlias  NextHop       RouteMetric
--------------  -------       -----------
Ethernet        192.168.1.1   0

Set a Static IP Address

To assign a static IP you need to remove the existing DHCP-assigned address and then create a new one. You also need to set the default gateway via New-NetRoute. This requires administrator rights.

# Remove existing DHCP address first
$adapter = Get-NetAdapter -Name "Ethernet"
Remove-NetIPAddress -InterfaceIndex $adapter.InterfaceIndex -Confirm:$false
Remove-NetRoute -InterfaceIndex $adapter.InterfaceIndex -Confirm:$false

# Set static IP
New-NetIPAddress -InterfaceIndex $adapter.InterfaceIndex `
    -IPAddress "192.168.1.50" `
    -PrefixLength 24 `
    -DefaultGateway "192.168.1.1"

# Set DNS servers
Set-DnsClientServerAddress -InterfaceIndex $adapter.InterfaceIndex `
    -ServerAddresses "8.8.8.8", "8.8.4.4"

Remote Network Info with CIM

To query network information on a remote computer, use Get-CimInstance with the Win32_NetworkAdapterConfiguration class. WinRM must be enabled on the remote host. This approach works without the NetTCPIP module being available on the remote machine.

$remotePC = "server01"
Get-CimInstance -ComputerName $remotePC -ClassName Win32_NetworkAdapterConfiguration |
    Where-Object IPEnabled -eq $true |
    Select-Object Description, IPAddress, DefaultIPGateway, MACAddress

Common Errors and Fixes

  • Multiple IP addresses per adapter: An adapter can have more than one IP address assigned — a static IP plus a DHCP fallback, for example. When your script expects a single value, use Select-Object -First 1 or filter explicitly: Where-Object { $_.IPAddress -like "192.168.*" } to get only the subnet you care about.
  • Requires admin to change IP settings: New-NetIPAddress, Remove-NetIPAddress, and Set-DnsClientServerAddress all require an elevated session. Run PowerShell as administrator or wrap the commands in a Start-Process powershell -Verb RunAs call from your deployment script.

Related Cmdlets / See Also

Wrapping Up

Get-NetAdapter, Get-NetIPAddress, and Get-NetRoute replace the text-parsing misery of ipconfig with clean, structured objects ready for filtering and export. As a next step, combine the remote CIM query with a list of computers from Active Directory to build a complete network inventory spreadsheet in minutes.

Send-Item -To