~/exporting dns records when your dns host has no export optionExporting DNS records when your DNS host has no export option
WordPress.com and some other DNS hosting providers won't export your DNS records. This PowerShell script rebuilds a zone file from the live records, ready to import into Azure DNS or Cloudflare.
If you’re moving a domain’s DNS to a new host, the safest first step is to export the existing zone. Most DNS hosts give you a button for it. WordPress.com doesn’t: you can view and edit your records, but there’s no way to download them.
You could copy them out by hand, but that’s where mistakes creep in. Miss an MX, SPF or DKIM record and your email stops working the moment you switch nameservers. So I wrote a script to do it instead.
The idea
A DNS zone transfer (AXFR) would give you the whole zone in one go, but almost every public DNS host refuses them, and DNS has no other way to list every name in a zone. What you can do is ask the domain’s nameserver about specific names.
Most domains have a fairly predictable set: the root and www, Microsoft 365’s records, DKIM selectors, DMARC and a handful of verification records. The script asks the authoritative nameserver directly about each of those names and writes everything it finds as a standard BIND zone file, which Azure DNS, Cloudflare and most other hosts can import.
Querying the authoritative nameserver rather than your normal resolver matters for two reasons. You get the answer straight from the source, and you get the real TTLs rather than whatever’s left on a cached copy.
Using it
The script is on GitHub: oasysadmin/Export-DnsZone.
.\Export-DnsZone.ps1
Because it’s downloaded from the internet, PowerShell may refuse to run it. Have a read through it first (good practice for any script), then remove the download mark with Unblock-File .\Export-DnsZone.ps1. If scripts are disabled on your machine altogether, Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass allows them for that PowerShell window only, and the setting ends when you close it. On a work machine, check with your IT team first, because the policy may be there on purpose.
It asks for the domain, then looks up its current nameservers and offers the first one. Press Enter to accept it. Then it asks whether there are any extra names to check. You can also pass everything as parameters:
.\Export-DnsZone.ps1 -Domain example.com -NameServer ns1.example-dns.net -AdditionalHosts shop,vpn
You get a file like this:
; Zone file for example.com, generated by Export-DnsZone on 2026-11-26 17:30
; Source nameserver: ns1.example-dns.net
; CHECK THIS AGAINST YOUR CURRENT DNS HOST'S RECORDS PAGE BEFORE IMPORTING.
; Only the names the script checks are included.
$ORIGIN example.com.
$TTL 3600
@ 3600 IN MX 0 example-com.mail.protection.outlook.com.
@ 3600 IN TXT "MS=ms12345678"
@ 3600 IN TXT "v=spf1 include:spf.protection.outlook.com -all"
www 3600 IN CNAME example.azurestaticapps.net.
autodiscover 3600 IN CNAME autodiscover.outlook.com.
_dmarc 3600 IN TXT "v=DMARC1; p=reject; rua=mailto:dmarc@example.com"
Always check the output against your current DNS host’s records page before you import it. The script can only find names it knows to ask about. If you have a subdomain it doesn’t check, add it with -AdditionalHosts and run it again. Any record you leave out stops working when you change nameservers, and for email records that means mail stops arriving.
The script also does three checks that are easy to forget:
- Wildcards. It asks for a name that can’t exist. If something answers, there’s a
*record, and it adds that to the export. - Delegated subdomains. If one of the names it checks has its own NS records pointing at another DNS host, it exports those NS records.
- DNSSEC. It warns you if the domain has DNSSEC switched on. More on why that matters below.
Importing into Azure DNS
In the portal, create the DNS zone, open it and select Import. Browse to the file, check it in the editor, then select Review + Create. From the command line:
az network dns zone import -g <resource-group> -n example.com -f example.com.zone.txt
Azure keeps its own NS and SOA records, so you don’t need to remove them from the file. Afterwards, check your TXT records, especially long ones, because multi-string values aren’t always imported exactly as they were.
Before switching nameservers, run the script again against one of the Azure nameservers and compare the two files, ignoring the comment lines at the top:
$old = Get-Content old.zone.txt | Where-Object { $_ -notmatch '^;' }
$new = Get-Content new.zone.txt | Where-Object { $_ -notmatch '^;' }
Compare-Object $old $new
Nothing should come back except changes you made on purpose.
What else can catch you out
Copying the records is only part of moving DNS. A few things break even when every record is right:
- DNSSEC. If it’s switched on, there’s a DS record at the registry that matches your old host’s signing keys. Move to new nameservers with that still in place and any resolver that checks DNSSEC will reject your whole domain: website, email, everything. Turn DNSSEC off at the registrar first, wait for the DS record to expire, then switch. You can switch it back on with the new host afterwards.
- Services the old host runs for you. Email forwarding, URL redirects and parked pages run on the old host’s servers. The DNS records point at them, but copying the records doesn’t move the service.
- Propagation. Nameserver changes can take up to 48 hours to reach everyone, so some people will still be using the old host for a while. Don’t delete or edit the old records until that’s passed.
- CAA records. The script doesn’t export them. Losing them just makes certificate issuance less restricted, but if you add new ones, make sure they allow every certificate authority your services use, or certificate renewals will fail.
Limitations
- It only finds the names it checks, so always compare with your host’s records page.
- It covers A, AAAA, CNAME, MX, TXT and SRV records, plus NS for delegated subdomains. Not CAA.
- Your old host’s own records come across too, such as A records pointing at its web servers. Remove any you’re replacing.
- Some corporate networks block DNS queries to anything but their own resolvers. If you get an empty result, try another network.
- It needs Windows, because
Resolve-DnsNameis a Windows cmdlet.
Disclaimer
The script is free to use under the MIT licence and comes without any warranty. It only reads DNS records and writes a file, so it can’t change anything by itself. What you do with the output is up to you, though, and a DNS mistake can take a website or email offline. Check the export against your current host, test the new zone before switching, and keep a copy of the old records.
Get the script
It’s on GitHub at oasysadmin/Export-DnsZone, along with a README that covers the full checklist for moving DNS. If you find a record name it should be checking, or a bug, open an issue there.