I am wanting to set a variable one line at a time from a text file, run a particular command using this variable, then loop back, grab the second line, process the command, and so on until the file ends.
The batch file works well and asks for user input, then processes using the input as the variable with no problems at all. The script gets the computer name first, then copies the install files to the local machine the uses WMIC to install the MSI:
@echo off
SET /P computer=Enter Computer Name
echo.
XCopy "\\server\netlogon\temp\*.*" "\\%computer%\c$\temp\*.*" /E /C /H /R /Y 
WMIC /Node:"%computer%" product call install true,"","c:\temp\msi_to_install.msi"
The text file will look something like this:
PC-01
PC-02
PC-27
Odd-PC
However, when I try to introduce a "for" loop, so that I can process a hundred or more machines one at a time, nothing happens. Even if I have only one line in the file I cannot get it to work. This is what I have tried:
@echo off
For /F %%i in (c:\test.txt) do (
set computer=%%i
echo.
XCopy "\\server\netlogon\temp\*.*" "\\%computer%\c$\temp\*.*" /E /C /H /R /Y 
WMIC /Node:"%computer%" product call install true,"","c:\temp\msi_to_install.msi"
)
For the record I have tried the variables with %%computer%% and !computer! with no success.
I have also tried the following also with or without the /p in the "SET" command:
@echo off
SET /P computer=<"c:\test.txt"
echo.
XCopy "\\server\netlogon\temp\*.*" "\\%computer%\c$\temp\*.*" /E /C /H /R /Y 
WMIC /Node:"%computer%" product call install true,"","c:\temp\msi_to_install.msi"
I would appreciate any suggestions or input.