Solved

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

Posted on 2013-06-14
4
739 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 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now