Solved

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

Posted on 2013-06-14
4
753 Views
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:

NYC-SERVER01 172.20.30.15
NYC-SERVER02 172.20.30.16
NYC-SERVER03 172.20.30.17

Thanks.
0
Comment
Question by:bsohn417
[X]
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
4 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39248847
You may get the information from AD itself.. Does that work for you?
Try..
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

0
 
LVL 8

Author Comment

by:bsohn417
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.
0
 
LVL 40

Accepted Solution

by:
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)
http://dnsshell.codeplex.com/
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

0
 
LVL 8

Author Comment

by:bsohn417
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 "domain.com" -server "DNShostname" -RecordType A | ?{$_.Name -like "NYC*" -and $_.RecordData -like "192.168.*.*"} | Select RecordData,Name | export-csv "C:\Temp\DNS Script\report.csv"
0

Featured Post

IoT Devices - Fast, Cheap or Secure…Pick Two

The IoT market is growing at a rapid pace and manufacturers are under pressure to quickly provide new products. Can you be sure that your devices do what they're supposed to do, while still being secure?

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

628 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