The dnscmd
utility from the Windows Support Tools is probably your best bet. You can get a list of all the DNS zones with the command: dnscmd [servername] /EnumZones
. You can enumerate all the CNAME records in each zone with the command: dnscmd [servername] /EnumRecords [zone name] . /TYPE CNAME
.
In theory you could chain these two together in a script, process the output, and make the changes you want automatically (also using dnscmd
with the /RecordDelete
and /RecordAdd
commands). That's an exercise I'll leave to you (for now).
Edit: Okay-- I couldn't resist. Here's that script. It will only echo
the commands that actually make changes. If it does what you want then you can pull the echo
commands out and let 'er rip.
@echo off
set SERVER_TO_REPLACE=server1.domain.com
set REPLACEMENT_VALUE=server2.domain.com
rem Quick and dirty list of Primary zones that aren't Reverse zones
for /F "usebackq" %%i in (`dnscmd %1 /EnumZones ^| find " Primary" ^| find /v " Rev"`) do call :process_zone %1 %%i
goto end
:process_zone
rem Quick and dirty enumeration of all CNAME records in a zone
for /F "usebackq tokens=1,3,4" %%i in (`dnscmd %1 /EnumRecords %2 . /TYPE CNAME ^| find " CNAME"`) do call :process_RR %1 %2 %%i %%j %%k
goto end
:process_RR
rem Check a record and alter it if necessary
if /I "%5" EQU "%SERVER_TO_REPLACE%" (
echo dnscmd %1 /RecordDelete %2 %3 %4 %5 /f
echo dnscmd %1 /RecordAdd %2 %3 %4 %REPLACEMENT_VALUE%
)
:end