Previously to PowerShell 3 this was the easiest way to resolve a hostname.
$IPAdr = [string][system.net.dns]::gethostaddresses("myhost.mydomain.net"])
This is fine except many native .NET calls seem to be a minefield of memort leaks and slow performance. Also there are some obvious limitations on flexibility, for example you would have to wrap this is more code if you only wanted an IPv4 address (this will return both).
Enter PowerShell 3...............!
Here is the same deal using the new 'Resolve-DNSName' cmdlet.
$IP = (Resolve-DnsName "myhost.mydomain.net" -type A)
Much nicer, much faster and much more flexible. True to the PowerShell architecture, this returns a .NET object. Let's explore an example. When I try 'www.google.com' the cmdlet returns:
Name Type TTL Section IPAddress
---- ---- --- ------- ---------
www.google.com AAAA 201 Answer 2607:f8b0:400e:c02::68
www.google.com A 201 Answer 126.96.36.199
www.google.com A 201 Answer 188.8.131.52
www.google.com A 201 Answer 184.108.40.206
www.google.com A 201 Answer 220.127.116.11
www.google.com A 201 Answer 18.104.22.168
www.google.com A 201 Answer 22.214.171.124
Interesting to see Google's IPv6 AAAA record.
So one of the properties is IP4Address which would return the following string:
Have fun exploring it!