Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want a batch file to pull information from the first line of a text file (notepad), use that information to add information to a DNS server, and then delete it. I'm thinking if I create a loop, I can make it go all the way through the text file, using the first line of information to add to the DNS server and then deleting the first line before starting a loop. For example... The batch file would be

@echo off
dnscmd "mydns" /zoneadd (need to know the command from here to add the FQDN from the text file)
::(Need to know the command here to delete the first line of the text file and save the file)
goto start 

The text file reads

So I want it to add to the dns, then delete it, start at the beginning of the text file, and add to the dns, delete it, and start from the beginning again until the text file is empty.

share|improve this question

There's no built-in primitive in CMD.EXE to delete lines from text files. I suspect you'd find utility in the for command.

@echo off
for /f %%i in (textfile.txt) do echo dmscmd "mydns" /zoneadd %%i

That will iterate thru all the lines in textfile.txt displaying the example dnscmd command-line for each line of the file. (Obviously, remove the echo to have it actually execute commands).

The syntax for for is somewhat arcane. When you use for at a bare command-prompt you don't double %% the environment variables. I find for to be incredibly handy and use it on a daily basis (but, then, I'm also at the command-prompt on a daily basis, too).

share|improve this answer
That was VERY helpful! One more thing I need though, if you can add it to the command above, I need each of the sites being added to the Forward Lookup Zones to have a loopback Host added (done in the GUI by right clicking in the window and selecting New Host (A) and inputting as the IP Address) what I have so far on the CMD is: for /f %i in (MasterTest.txt) do dnscmd /zoneadd %i That adds it to the dns but doesn't input the loopback. :) if you could help me with that I'd be very appreciative. – Joshua Cavalucci Aug 17 '11 at 1:50
Look at my answer to your other question. – Evan Anderson Aug 17 '11 at 1:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.