Shane Corellian
posted this on November 28, 2011 15:20
Robocopy is a fantastic copy utility that I have used for years. There is one small gotcha when using Robocopy, however. The "gotcha" has to do with Exit Codes (AKA Error Codes, AKA Return Codes).
Exit Code 0 is, for the most part, the code that most processes, applications and installers use when NO errors were encountered. A non-zero exit code generally means that there was a problem encountered somewhere.
For Robocopy, Exit Code 0 means that there were NO errors and that NO files were copied. (this way you know that if there were any new files to be copied that they would have been but the source and target directories are already synchronized).
Exit Code 1 means that one or more files copied SUCCESSFULLY! This means that you need to define the exit code 1 to your list of Successful Return Codes.

Here is a site containing the Exit Codes for Robocopy.
Keep in mind that Error 16 usually means that there is a permissions error on either the Target or Source directories. Make sure that the credentials you are using with PDQ Deploy have the appropriate rights on both the target computer (must have administrative rights) and the source directory (must be able to see, access and copy from source). You can see the credentials you are using in the Deploy Now window. In the example below, the use account GConstanza in the Vandalay domain must be an Administrator of the all the target machines AND must be able to see and copy files from the \\Scranton\e$\deploy\OpenZone directory. (source directory referenced in image above)

Comments
You can use this information in a batch file to report the most serious anomalies, as follows:
if errorlevel 16 echo ***FATAL ERROR*** & goto end
if errorlevel 8 echo **FAILED COPIES** & goto end
if errorlevel 4 echo *MISMATCHES* & goto end
if errorlevel 2 echo EXTRA FILES & goto end
if errorlevel 1 echo Copy successful & goto end
if errorlevel 0 echo --no change-- & goto end
:end
Alternatively, full details of the return code could be reported as follows:
if errorlevel 16 echo ***FATAL ERROR*** & goto end
if errorlevel 15 echo FAIL MISM XTRA COPY & goto end
if errorlevel 14 echo FAIL MISM XTRA & goto end
if errorlevel 13 echo FAIL MISM COPY & goto end
if errorlevel 12 echo FAIL MISM & goto end
if errorlevel 11 echo FAIL XTRA COPY & goto end
if errorlevel 10 echo FAIL XTRA & goto end
if errorlevel 9 echo FAIL COPY & goto end
if errorlevel 8 echo FAIL & goto end
if errorlevel 7 echo MISM XTRA COPY & goto end
if errorlevel 6 echo MISM XTRA & goto end
if errorlevel 5 echo MISM COPY & goto end
if errorlevel 4 echo MISM & goto end
if errorlevel 3 echo XTRA COPY & goto end
if errorlevel 2 echo XTRA & goto end
if errorlevel 1 echo COPY & goto end
if errorlevel 0 echo --no change-- & goto end
:end