Given a number of records that need to be added to DNS, we can create a file with the necessary information, and then run a cmd to read the data in the file and create the necessary records in DNS. The following assumes that all records are to be created in the same zone.
- Create a CSV file with no header. The three columns should include only the following…
NodeName,RRType, RRDataFor example, if you wanted to create an A record for server1 at 1.2.3.4, and a CNAME for fp1 that resolves to the FQDN server1.example.com, your file would look like this…
server1,A,1.2.3.4
fp1,CNAME,server1.example.com - The following command line will do the trick. If using Vista or 2008, run this from an Administrative cmd prompt.
for /f “tokens=1-3 delims=,” %G IN (list.txt) do dnscmd serverfqdn /recordadd zonefqdn %G %H %I
To break this down, “tokens=1-3″ means to use all three columns.
“Delims=,” just means that the delimiting character in the file is a comma.
“%G” sets the first variable…you could have used any letter or number you want as long as you stay in order for the rest.
“list.txt” is of course the name of the CSV file you are going to use.
“do dnscmd serverfqdn /recordadd zonefqdn %G %H %I“ executes the command against the DNS server serverfqdn (you could use the ip.addr)
“zonefqdn” means to use the zone’s fqdn, eg. example.com
If you have multiple zones you wish to manage in one file, make the first column zonefqdn, and add %J at the end of the cmd-line.
Hopefully this will help someone else out…if not, I expect I will need to refer to this again many times over the next few months!
You might also enjoy:






{ 1 comment… read it below or add one }
http://dns-info.blogspot.com/2009/02/create-host-record-using-dnscmd.html