PowerTip: Use PowerShell to Get IP Addresses

PowerTip: Use PowerShell to Get IP Addresses

  • Comments 4
  • Likes

Summary: Use Windows PowerShell to retrieve IP addresses.

Hey, Scripting Guy! Question Is there a way to use Windows PowerShell to check IP addresses without use IPconfig?

Hey, Scripting Guy! Answer In Windows Server 2012 R2, use the new Get-NetIPAddress cmdlet:


If you like the output in a table, use:

Get-NetIPAddress | Format-Table

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Or you could old school it with about any version of powershell
    $ip=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1}
    Will get you the ipv4 data

  • This is fantastic!

    Is it possible to filter this such that it will only show the connected/active IP addresses?



  • I like to do this with $IP = test-connection "PCname" -timetolive 2 -count 1; $ip=$ip.ipv4address.

    I also check for DNS conflicts by doing this:
    $ip1=test-connection $computername -count 1 -timetolive 5; $ip2=$ip1.ipv4address
    $N2= ([system.net.dns]::gethostbyaddress("$ip2")).hostname
    $N1= ([system.net.dns]::gethostbyName("$computername")).hostname
    $p3=test-connection $N2 -count 1 -timetolive 5; $ip4=$ip3.ipv4address
    IF($N1 -eq $N2) {
    $Outcome="$computername is on the Network and has no IP conflicts with $n1, the IP address is $ip2"
    } else {
    $outcome="$computername has an IP conflict with $n2 with $n1 has an IP address of $ip2, This Ip address also points to $n2 with ip $ip4"