Script to Extract Specific Hostnames and IP Info from Active Directory DNS

Posted on 2013-06-14
Last Modified: 2013-06-18
Anyone know of an easy way to script the below against Active Directory DNS?

Query DNS and extract any hostnames with NYC- and with a 172.20.30.x IP, and output hostname and IP to a text file.  

Examples that should show up in the text file are:


Question by:bsohn417
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 40

Expert Comment

ID: 39248847
You may get the information from AD itself.. Does that work for you?
Get-ADComputer -Filter 'Name -like "NYC*"' -Properties IPv4Address | Select Name,DNSHostName,IPv4Address,`
	@{N="Ping Status";E={If(Test-Connection $_.DNSHostName -EA Silentlycontinue -Count 1){"Pinging"}Else{"Not Pinging"}}} |
	Export-Csv C:\report.csv -NTI

Open in new window


Author Comment

ID: 39248860
Thanks for your response, Subsun.  Will this extract machines from the 172.20.30.x network only?  I have other networks but do not want to export that info.  Thanks.
LVL 40

Accepted Solution

Subsun earned 500 total points
ID: 39248892
Nope.. I missed that part.. :-) .. It is possible to add filter to above code however it will be an overhead..

You can use DnsShell (It's a free module)
Get-DnsRecord -RecordType A | ?{$_.Name -like "NYC*" -and $_.RecordData -like "172.20.3.*"} | Select Name,RecordData | Export-Csv C:\report.csv -NTI

Open in new window


Author Comment

ID: 39257639
Thanks Sunsun!  I got this to work, but needed to add the -zone and -server parameters.  I also removed -NTI as I was getting an error from it for some reason.  Appreciate all the help!  

Get-DnsRecord -zone "" -server "DNShostname" -RecordType A | ?{$_.Name -like "NYC*" -and $_.RecordData -like "192.168.*.*"} | Select RecordData,Name | export-csv "C:\Temp\DNS Script\report.csv"

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question