Powershell to retreive NS records for multiple zones

Hi guys,

I've got about 100 domains on my my DNS server, a mixture of Primary & Secondary, AD integrated and not, and I need to get a list of all these and their corresponding Namservers, in a presentable format.

I do not need any other zone info or records, just -

Zone A - NS1, NS2
Zone B - NS1, NS2
etc

As I am trying to learn Powershell I wondered if someone could show me how to script this, and format in a way so that each zone is on a new line when exported (as some zones obviously have many NS's)?

Thank you for your time!
Dave
undercover69Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

I can deal with this very easily if I make you download my DNS module (you'll need PowerShell 2, but it's not something you have to pay for):

http://code.msdn.microsoft.com/dnsshell

If you don't go down that road it needs a lot of messing around in WMI. It's possible, that's how my module does it, but I'd rather save you the pain, the WMI interface for DNS is not fun to work with.

If you went for straight CSV the code is a lot simpler, it's only shifting the zone name and all name servers onto the same line that adds complexity.

Chris
Get-DnsRecord -Type NS -Server YourDnsServer | Group-Object Name | %{
  "$($_.Name)  $([String]::Join(', ', $($_.Group | %{ $_.RecordData })))" }

Open in new window

0
undercover69Author Commented:
Hi Chris,

That's great, thanks very much.

Could I trouble you for the code to go straight to CSV as well?

Thanks again.
Dave.
0
Chris DentPowerShell DeveloperCommented:
Sure, no problem.

Modified slightly so it puts the values into columns.

Chris
Get-DnsRecord -Type NS -Server YourDnsServer | Group-Object Name |
  Select-Object @{n='ZoneName';e={ $_.Name }},
    @{n='NameServers';e={ "$($_.Group | %{ $_.RecordData })" }} |
  Export-CSV "SomeFile.csv"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
undercover69Author Commented:
Top man,
thanks Chris!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.