Quickly Getting IP Addresses

by Aug 12, 2015

You want to quickly get a list of IP addresses for your own computer or a network machine? Here is how:

#requires -Version 3

$ComputerName = ''

[System.Net.Dns]::GetHostAddresses($ComputerName).IPAddressToString 

To only get IPv4, try this:

#requires -Version 1

$ComputerName = ''

[System.Net.Dns]::GetHostAddresses($ComputerName) |
Where-Object {
  $_.AddressFamily -eq 'InterNetwork' 
} |
Select-Object -ExpandProperty IPAddressToString

Likewise, to get IPv6, adjust to this:

#requires -Version 1

$ComputerName = ''

[System.Net.Dns]::GetHostAddresses($ComputerName) |
Where-Object {
  $_.AddressFamily -eq 'InterNetworkV6' 
} |
Select-Object -ExpandProperty IPAddressToString

Twitter This Tip! ReTweet this Tip!