Solved

DNS Export List Command Line or Script?

Posted on 2008-06-17
5
1,894 Views
Last Modified: 2008-07-04
On a Server 2003 DNS server, I can go into DNS and right-click a zone and "Export List".

Is there a way to do this in a command line or in a script, such as WMI?

I tried using dnscmd /WriteBackZone ("write back zone to file") but it won't let me specify the file and I can't find any file that it supposedly wrote back to.

I don't care what the method is, as long as I can incorporate it into some kind of script.

Thanks.
0
Comment
Question by:gateguard
[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
  • 3
5 Comments
 

Expert Comment

by:jlib99
ID: 21803532
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 21804380

All files written by DNSCMD are placed in %SystemRoot%\System32\DNS\.

You can export the zone in it's entirety. e.g.:

dnscmd server1 /ZoneExport domain.com domain.com.dns.txt

Where domain.com.dns.txt is the file name and will be in the path above on server1.

It is all exposed in WMI as well, so, depending on what you'd like to do with it, you might find that more useful. I can provide specific examples if you need.

Chris
0
 

Author Comment

by:gateguard
ID: 21805093
Thanks, Chris.  /ZoneExport only works on 2003 servers and I want to run the script from a 2000 server so if you happen to have a WMI script to do the same thing I would be greatly grateful.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 21916176

Sure, give me a little time, I'll have to rebuild the zone entirely from the various pieces of WMI.

Afraid I have nothing to test it against either, I'll have to bug you to do that bit for me :)

Chris
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 21933312

This will build a fairly basic version of the zone from WMI. Correct the File and Zone name values at the top.

Service Records are quite a bother to extract, do you need those?

Chris

Const ZONE_NAME = "domain.com"
Const ZONE_FILE = "domain.com.dns"
 
Function GetSOARecord
	Dim colItems
	Dim objItem
	Dim strRecord
 
	Set colItems = objWMIService.ExecQuery("SELECT * FROM MicrosoftDNS_SOAType " &_
		"WHERE DomainName='" & ZONE_NAME & "'", "WQL")
 
	For Each objItem in colItems
		strRecord = "@" & VbTab & " IN SOA " & objItem.RecordData & VbCrLf
	Next
 
	Set colItems = Nothing
 
	GetSOARecord = strRecord
End Function
 
Function GetNSRecords
	Dim colItems
	Dim objItem
	Dim strRecords
 
	Set colItems = objWMIService.ExecQuery("SELECT * FROM MicrosoftDNS_NSType " &_
		"WHERE DomainName='" & ZONE_NAME & "'", "WQL")
 
	For Each objItem in colItems
		strRecords = strRecords & "@" & VbTab & " IN NS " &_
			objItem.RecordData & VbCrLf
	Next
 
	Set colItems = Nothing
 
	GetNSRecords = strRecords
End Function
 
Function GetMXRecords
	Dim colItems
	Dim objItem
	Dim strRecords
 
	Set colItems = objWMIService.ExecQuery("SELECT * FROM MicrosoftDNS_MXType " &_
		"WHERE DomainName='" & ZONE_NAME & "'", "WQL")
 
	For Each objItem in colItems
		strRecords = strRecords & "@" & VbTab & " IN MX " &_
			objItem.RecordData & VbCrLf
	Next
 
	Set colItems = Nothing
 
	GetMXRecords = strRecords
End Function
 
Function GetCNAMERecords
	Dim colItems
	Dim objItem
	Dim strRecords, strNode
 
	Set colItems = objWMIService.ExecQuery("SELECT * FROM MicrosoftDNS_CNAMEType " &_
		"WHERE DomainName='" & ZONE_NAME & "'", "WQL")
 
	For Each objItem in colItems
		strNode = Replace(objItem.OwnerName, "." & ZONE_NAME, "", 1, -1, VbTextCompare)
		strRecords = strRecords & strNode & VbTab & " IN CNAME " &_
			objItem.RecordData & VbCrLf
	Next
 
	Set colItems = Nothing
 
	GetCNAMERecords = strRecords
End Function
 
Function GetARecords
	Dim colItems
	Dim objItem
	Dim strRecords, strNode
 
	Set colItems = objWMIService.ExecQuery("SELECT * FROM MicrosoftDNS_AType " &_
		"WHERE DomainName='" & ZONE_NAME & "'", "WQL")
 
	For Each objItem in colItems
		strNode = Replace(objItem.OwnerName, "." & ZONE_NAME, "", 1, -1, VbTextCompare)
		strRecords = strRecords & strNode & VbTab & " IN A " &_
			objItem.RecordData & VbCrLf
	Next
 
	Set colItems = Nothing
 
	GetARecords = strRecords
End Function
 
 
Dim objWMIService, objFileSystem, objFile
 
Set objWMIService = GetObject("winmgmts:\\.\root\MicrosoftDNS")
 
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.OpenTextFile(ZONE_FILE, 2, True, 0)
 
objFile.WriteLine GetSOARecord
objFile.WriteLine GetNSRecords
objFile.WriteLine GetMXRecords
objFile.WriteLine GetCNAMERecords
objFile.WriteLine GetARecords
 
Set objFile = Nothing
Set objFileSystem = Nothing
 
Set objWMIService = Nothing

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DNS Issues With Machines 2 55
Skype for Business server 6 73
What is a standalone domain controller? 8 52
Cannot access website or email server 4 86
If you have a multi-homed DNS setup in windows, you can have issues with connectivity to the server that hosts the DNS services (or even member servers of your domain if this same DNS server is a DC). This is because windows registers all of its IPs…
I've written instructions for one router type, but this principle may be useful for others of the same brand and even other brands of router. Problem: I had an issue especially with mobile devices that refused to use DNS information supplied via…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

751 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