Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
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 update 100 user accounts from an external text file. View in 1080p for best video quality.

877 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