I have a batch file that attempts to copy a file from my local machine to hundreds of network machines using RoboCopy. These machines may not be powered on or connected to the network. If this is the case, the error that is returned is "The network path was not found".
I am ok with this error, but I want to do something if this error is found. I am just now learning about batch files and I am not sure how to implement this in an IF statement.
FOR /F %%X IN (SISComputerList.txt) DO (
robocopy.exe "Source Directory" "%%X" (FileToCopy) /R:0
ECHO %ERRORLEVEL%
IF %ERRORLEVEL$ LEQ 2 (
Echo %%X >> Logfile.txt
Echo Fail
) ELSE (
ECHO PASS
)
)
@echo Completed
In this code, even if there is a network error, it goes into the "Else" block with ErrorLevel 1.