|Hi, I have a simple script that copies a file to each computer contained in txt file.|
I'm using the For /f to read the computer names, then I ping the computer and only if it's on the network do I try to copy the file.
The problem is the that the Ping cmd does not return the proper errorlevel when used in the For loop. When I used ping form cmd line it does return the proper ErrorLevel. I thought the problem was caused by the lack of the DelayedExpansion but using !ErrorLevel! instead of %EverLevel% does not work.
The script works but it ties to copy files even on computer that are not pingable, I've set Xcopy to ignore error but it takes the script a long time to run as it times out on the machine that are not reachable.
Any suggestions ?
FOR /F "tokens=1" %%a IN (mtl_computers.txt) do (
@echo Copying file to computer %%a
ping -1 n %%a >nul
if ERRORLEVEL 0 (xcopy custom.prf "\\%%a\c$\Program Files\Microsoft Office\custom.prf" /U /C /Y) else (echo do nothing)