Migrate DNS to Windows

While there are better ways to migrate DNS (like zone transfers), the tech who setup AD didn’t transfer the records before the server was delivering services. Instead of risking a zone transfer with AD already running with DNS, and DNS partially populated, I just dumped the current DNS records into a series of powershell commands.

Line 4 is querying our current DNS server for each of the records in an IP range, echoing out only IPs which have hostnames, and removing the domain from each of the FQDNs.

#!/bin/bash i=1; while [ $i -lt 255 ]; do host=`nslookup xxx.xxx.xxx.$i | grep name.= | awk '{print $4}' | sed 's/..*//'`; if [ `echo $host | grep -c "[a-z]"` -eq 1 ]; then echo Add-DnsServerResourceRecordA -ZoneName domain-name -Name $host -IPv4Address xxx.xxx.xxx.$i -CreatePtr; fi; ((i++)); done;

What you get in the end is something you can copy/paste into PowerShell