[PowerShell] Do Reverse DNS Lookup On A List of Servers & Vice Versa

A handy little script (you don't need to save it as a script, you can just run it directly in PowerShell.) Set the highlighted infileNamePath and outfileNamePath as per your requirements (I've left some example data in there.) Each line in the text file is a servername you want to find the IP of.

  • $infileNamePath = "Z:\serverlist.txt"
  • $outfileNamePath = "Z:\serverlist-resolved.csv"
  • $Results = @()
  • Get-Content $infileNamePath | Foreach{
  • $Results += Resolve-DnsName -type A -Name $_ -ErrorAction SilentlyContinue
  • }
  • $Results | Select Name,IPAddress | Export-CSV $outfileNamePath -NoTypeInformation
If you want to do a DNS lookup on a list of IP addresses:
  • $infileNamePath = "Z:\serverlist.txt"
  • $outfileNamePath = "Z:\serverlist-resolved.csv"
  • $Results = @()
  • Get-Content $infileNamePath | Foreach{
  • $Results += Resolve-DnsName -type PTR -Name $_ -ErrorAction SilentlyContinue
  • }
  • $Results | Select NameHost | Export-CSV $outfileNamePath -NoTypeInformation

Comments