Robocopy exit codes
Robocopy is a great tool, and I often use it in a deployment project for moving files around; I think the most useful feature it has is the /MIR switch. It lets you update the contents of a folder, only copying the files that have changed or are missing.
One problem with the use of Robocopy in the task sequence is that it doesn't always return an error code of 0, even if the copy has been successful. This can give a problem if you have your task sequence set up similar to the screenshot below. As you can see, I have added the Robocopy command direct to the task sequence, and I have left the default "Success codes" on the options tab. This works fine for most scenarios, but with Robocopy you might find that your deployment fails stating that Robocopy returned a non-success code, even though the copy appears to have been successful.
There are several ways to fix this, but the way I prefer is to add the additional success codes to the task sequence, that way it will only fail if a genuine error occurs. So, below I have included a list I compiled of the codes I have come across (I have included the non-success codes I have seen for completion). Feel free to comment on this post if you can help expand the list!
|0||No errors occurred and no files were copied.|
|1||One of more files were copied successfully.|
|2||Extra files or directories were detected. Examine the log file for more information.|
|4||Mismatched files or directories were detected. Examine the log file for more information.|
|8||Some files or directories could not be copied and the retry limit was exceeded.|
|16||Robocopy did not copy any files. Check the command line parameters and verify that Robocopy has enough rights to write to the destination folder.|
I strongly recommend that you use the /LOG parameter with Robocopy in order to create a complete log file of the process. This file is invaluable for finding out what went wrong.
This post was contributed by Daniel Oxley a consultant with Microsoft Services Spain