• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1094
  • Last Modified:

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
0
undercover69
Asked:
undercover69
  • 2
  • 2
1 Solution
 
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
 
undercover69Author Commented:
Top man,
thanks Chris!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now