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

Comments

Popular posts from this blog

NSX-T: Release associated invalid node ID from certificate

NSX-T: vCenter and NSX-T Inventory out of Sync (Hosts in vSphere not showing up in NSX-T)

MacOS: AnyConnect VPN client was unable to successfully verify the IP forwarding table modifications.