Problem:
I have a DOS command I want to run against a list of variables, how can I accomplish this?
Solution:
Here are some examples using the FOR DO loop
(CAUTION: lines wrapped for readability!)
FOR /F %%s in (’type c:\serverlist.txt’) DO
copy "file.txt" \\%%s\d$\file.txtFOR %%S in (server1,server2,server3) DO
copy "file.txt" \\%%s\d$\file.txtFOR /L variable in (start,step,end) do command
For /L %%s in (1,1,10) will start at 1,increment by 1 and stop when it hits 10Give a domain user group full access to a directory (all one line)
FOR /F %%s in (’type c:\serverlist.txt’) DO
\\server\share\subinacl /subdirec
\\%%s\d$\exampledir /grant="domain\usergroup"=F
IMPORTANT NOTES: if you are running the above in a command line, the variable is with one %. If you are running commands in a batch file, the variable must be %%x. The variable is CASE SENSITIVE and can be any single letter. Use for /? to get more info at the command line.
Some of you may be wondering why in this day and age you would be bothering with DOS. One example I can give is with a Citrix farm. Let’s say you want to copy a file to twenty servers, the quickest way I can think of is with the command above and a text file that lists the target servers. It also comes in handy for deleting files,modifying permissions on files,directories,registry keys. Pretty much anything that involves a good amount of target systems and the same actions over and over.
