?
Solved

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

Posted on 2013-06-14
4
Medium Priority
?
755 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

718 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