Using PowerShell to Perform a Reverse DNS Lookup in Active Directory

Typically, one would use ping -a to get the hostname for a specific IP address which performs a DNS reverse lookup.
Querying AD for a computer with an IP works great for computers joined to the Active Directory domain since most computers in AD have the IP Address configured on the computer account. When the computer is joined to the domain, there are several attributes populated which are updated periodically, such as ipv4address, operatingsystem, operatingsystemversion, servicepack, etc.

Perform a IP Lookup Using PowerShell to find the associated computer (AD cmdlets):
import-module activedirectory
$ComputerIPAddress = ‘10.10.10.10’
Get-ADComputer -property * -filter { ipv4address -eq $ComputerIPAddress }


Perform a DNS Reverse Lookup (IP to hostname) Using PowerShell (.Net):

$ComputerIPAddress = ‘10.10.10.10’
[System.Net.Dns]::GetHostEntry($ComputerIPAddress).HostName

Get IP from Hostname Using PowerShell (.Net):
$ComputerName= ‘MetcorpDC01’
[System.Net.Dns]::GetHostAddresses(“$ComputerName”).IPAddressToString

 

(Visited 32,827 times, 20 visits today)