Today there was a question on one of the lists I’m on, it went something like this:
Has anyone written a tool that will batch-update WITD to all team projects on a server? Surely this must be a common scenario?
One of the built-in Windows commands that I use daily is the “FOR” command. Here’s how simple it is to upload a new Bug.xml for a list of projects.
for %a in ("Project 1", "Project 2", "Project 3") do witimport /f Bug.xml /t http://tfsserver:8080 /p %a
for %a in ("Project 1", "Project 2", "Project 3") do witadmin importwid /s http://tfsserver:8080/tfs/CollectionName /p %a /f Bug.xml
If you wanted to get fancy, you could even create a teamprojects.txt file with a team project name per line, and use the /F parameter to read them from a file. There are a few subtleties with that though, make sure you quote any parameters that need quoting:
for /F %a in (teamprojects.txt) do witimport /f Bug.xml /t http://tfsserver:8080 /p “%a”
And the last example for today is if you want to run the same command on every file in a directory. I use this all the time with relog.exe, when I want to concatenate a directory of perfmon logfiles (one for each hour) and change them to a different format. For example:
for /R %a in (*.blg) do relog %a –f CSV –o output.csv –a
Also remember, if you want to use the “FOR” command from within a batch file, you need to use %%a instead of just %a.