My Profile Photo
name := "Graham Beer"

`Cloud Engineer with his head in the AWS clouds, authored chapters in the PowerShell Conference Book 1 & 2 and currently learning and enjoying Go


PowerShell Conf Book Planet PowerShell Top 50 PowerShell

PS Function : IP to Hostname / Hostname to IP

Here is a short reusable function that came about when I recently had an error popup with just an IP address.

Turned out it was error many users were getting that caused a problem in the company. From the IP address I wanted to get the Hostname to ask the Wintel department if they knew of this Server.  I could have simply used the “Ping” command with a ‘-a’ option, but I wanted to find a way in PowerShell and create a function as a simply to use tool. As I was creating a function to find a Hostname from an IP why not do the reverse as well and get the IP from a Hostname. This is what I did, and by using the .NET class, “system.net.dns”, was able to achieve this. I hope you find it of some use in your day to day troubleshooting !

Example:

Get-NetDetails -HostName lhr25s01-in-f4.1e100.net
Get-NetDetails -IP 216.58.213.68