Windows PowerShell One Liner: Name to IP Address

Windows PowerShell One Liner: Name to IP Address

Rate This
  • Comments 19

<Edited 7/2/2006 to add tags and category>
Wei Wu provided a nice one liner in response to a query in our NewsGroup: Microsoft.Public.Windows.PowerShell about how to resolve a hostname into an IP Address:

PS> [System.Net.Dns]::GetHostAddresses("www.msn.com")


IPAddressToString : 207.68.173.76
Address           : 1286423759
AddressFamily     : InterNetwork
ScopeId           :
IsIPv6Multicast   : False
IsIPv6LinkLocal   : False
IsIPv6SiteLocal   : False

 

If you want to go from address to name:

PS> [System.Net.Dns]::GetHostbyAddress("207.46.198.30")

HostName                  Aliases                  AddressList
--------                  -------                  -----------
wwwtkttest2.microsoft.com {}                       {207.46.198.30}

Jeffrey Snover
Windows PowerShell Architect

PSMDTAG:FAQ: How do I resolve a hostname?
PSMDTAG:DOTNET: GetHostByAddress

Leave a Comment
  • Please add 3 and 3 and type the answer here:
  • Post
  • The .net framework provided that one, not Wei Wu.

  • In PowerShell v3 (because it uses .NET 4.0), the GetHostByAddress() method is obsoleted.  I have a blog post on the replacement method recommended by Microsoft and the problems it causes here: blog.forrestshields.com/.../Resolving-Reverse-DNS-Lookups-in-PowerShell.aspx

  • good stuff.  just found it 6 years later.

  • Works As Advertised!  I just found this 8 years later.

Page 2 of 2 (19 items) 12