Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file - cycle through array of numbers?

Status
Not open for further replies.

jrwinterburn

IS-IT--Management
Jul 26, 2004
72
GB
Hi all,

I have a batch file which will copy an updated copy of a file onto all the PCs in the domain. However, there are 80 PCs it has to copy to, and I'm not sure how to make the batch file cycle through all the PCs without having to enter each command.

The command is:

xcopy C:\MyProg\MyProg.exe \\PC1\C$\MyProg /c /f /y /z

I want to run this one command against all PC names - which are named as such: PC1, PC2, PC3 and so on up to PC80. How can I replace PC1 in that command to cycle through 1-80?

Thanks.

Jon
 
Not to worry - managed to figure out through trial and error!

I used the following:

FOR /F %%i IN (C:\MyProg\pc-list.txt) DO xcopy C:\MyProg\MyProg.exe \\%%i\C$\MyProg /C /F /R /V /Y

...and then exported the PC names from Active Directory into pc-list.txt so that the batch file could loop through the names by reading the file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top