Useful Powershell .NET method to convert DNS name to IP

Just thought this was useful, so decided to post it as a reminder for myself or anyone else really.
[system.net.dns]::gethostaddresses("www.vmware.com")

The reverse being:
[system.net.dns]::gethostbyaddress("23.64.19.51")

Here is how I used it w/ PowerCLI:
$VMHosts = Get-VMhost
$VMHosts | select Name, @{Name="IP";Expression={[system.net.dns]::gethostaddresses($_.Name)}}

This information can be particularly useful if you need IP's for firewall rule tables. Source: http://blogs.msdn.com/b/powershell/archive/2006/06/26/647318.aspx

No comments: