PowerShell: What Computer is that IP?

Oftentimes I receive an alert about a server, but the only information I have to work with is an IP address. Luckily, with the help of PowerShell and Active Directory, I was able to write a script to pull the computer name and some information on what that computer does.

The script is short, but a bit complicated. The first variable acquires the computer name via the IP address.  That alone is enough if you have few servers, but with the number I deal with, oftentimes I need a bit more information.

The second part of the script splits the hostname up, removing any extra information and leaving just the computer name.  Afterwards that value is piped to Get-AdComputer and then formatted as an easy to read table with minimal information. It returns what Organizational Units the computer is in, which should tell you what purpose your mystery IP serves. If you are lucky enough to have a description listed in AD, it will return that as well.

$IP = ""
$HostName = ([System.Net.DNS]::GetHostByAddress($IP)).HostName
$Hostname.Split('.')[0] | 
  Get-AdComputer | 
    FT Name,Description,DistinguishedName -AutoSize

2 thoughts on “PowerShell: What Computer is that IP?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s