brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Get-NetIPAddress lists the IP addresses of your Windows PC in a clean table

Windows
~/tips/tip-windows-get-netipaddress-ipv4

Get-NetIPAddress -AddressFamily IPv4 | Format-Table InterfaceAlias, IPAddress, PrefixLength

Lists the IPv4 or IPv6 addresses configured on each network interface of a Windows PC.

ipconfig prints a wall of text with every adapter, including the ones you do not care about. PowerShell can give a table with just the addresses.

Get-NetIPAddress -AddressFamily IPv4 | Format-Table InterfaceAlias, IPAddress, PrefixLength

The cmdlet gets the IP address configuration: IPv4 addresses, IPv6 addresses and the interfaces they belong to. The -AddressFamily parameter takes IPv4 or IPv6 and returns only matching entries. The Format-Table part keeps three columns: the adapter name, the address and the prefix length.

With a bit more PowerShell you can leave out the loopback address and the self-assigned ones, which makes the answer even shorter:

Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' } | Select-Object InterfaceAlias, IPAddress

The prefix length is the number after the slash in a notation like 192.168.1.20/24, so you see the network size without decoding a subnet mask.

The caveat is that the cmdlet is part of the NetTCPIP module, which ships with Windows. A Microsoft article that uses it warns that some commands do not work in the older PowerShell that comes with Windows Server, and suggests PowerShell 7 instead. It also only shows addresses on this machine. For the public address as the internet sees it, you need to ask an outside service.

Further reading: Microsoft Learn: Get-NetIPAddress

More Windows tips Win+Ctrl+C Win+Shift+Left arrow Win+Ctrl+Left arrow Alt+PrtScn Left Alt + Left Shift + Print Screen All Windows tips (33) All topics

Link