With PowerShell v3 comes some new DNS cmdlets. One of them is the Export-DnsServerZone cmdlet. This replaces some of the functionality of the old “DnsCmd” command line utility.
Actually, if you run DnsCmd on Windows 2012, it actually tells you that if you currently use DnsCmd.exe to configure and manage the DNS server, Microsoft recommends that you transition to Windows PowerShell.
So, on to Export-DnsServerZone. I thought great, that’s excellent news, instead of having to worry about getting PowerShell to execute the old dnscmd.exe and worry about its arguments etc., I’ll use the built in cmdlet to do the job.
Here is an example of what the command looks like.
If you were to substitute the name for the DNS zone you would like to export, and the filename for something that better describes your zone, that example will output a text file in to the %windir%\system32\dns folder.
So then, you can have your backup software come along and back it all up for you and everyone is happy.
Except, if you would like to modify that –Filename parameter to have it point to an actual file location like “C:\export.txt”. It doesn’t seem to work and you will get an error saying “Export-DnsServerZone : Failed to export the zone content for <your domain> on server <your server> to the file
<your file location>”
When you look up the online help for the cmdlet, it does specify that you can put a file path in the parameter. As shown below.
It doesn’t seem to accept UNC path either.
But it does seem to accept, a relative path. (The following command should put the text document in the root of C:\.
Here is the link to the online help for the Export-DnsServerZone cmdlet.
http://technet.microsoft.com/en-us/library/jj649939(v=wps.620).aspx
Thanks for the info! I would say that this is a bug and hopefully they fix it in future updates. I see you logged it here: http://connect.microsoft.com/PowerShell/feedback/details/790157/export-dnsserverzone-filename-parameter-doesnt-accept-literal-file-path
Did you post it somewhere else for Microsoft to see?
I haven’t no. Apathy kicked in 🙁 Hoping it will be fixed in Powershell 4.0.
Unfortunately this hasn’t been fixed in Powershell 4.0. What a pain.
When executed against a remote DNS Server, this puts the file on the given DNS Server into the given path (by Default into the %systemroot%\system32\DNS path), not on the machine where the command is executed.
Thanks for the info. This was driving me crackers. And yes, still b0rked on Server 2012 R2.
if you put the file name in not a path it is in C:\Windows\system32\dns and the filename
Thank you man!
Still broken in 2016… sad.