When generating reports for servers, I frequently find myself needing to either find the host name of a machine from its IP or the IP from its host name. I could not find a native cmdlet to achieve this, so I began poking around MSDN and came across the DNS class in the System.Net namespace for .NET.
To lookup the IP based on hostname, try the following:
$ServerName = "WindowsPC"
To do a reverse lookup from the IP to a hostname, try the following:
$IP = “192.168.0.1”
It is worth noting that the GetHostEntry method will work with either an IP address or a host name. The information returned by GetHostAddress is slightly different from that returned by GetHostEntry. It is worth taking a look at both to see which will work best for you.
for more information on System.Net.DNS, take a look at the MSDN page: http://msdn.microsoft.com/en-us/library/b8hth2dy(v=VS.100).aspx