Robocopy and Task Sequence

Robocopy and Task Sequence

Hi all,

Sometimes we need copy files from the server to the client during OS deployment, but if you’re a large organization with many physical locations, copying files from a specific location may not be suitable as it may cause copying files from the WAN link.

Due this, people of use DFS or use SCCM to do it creating CMD files to run as a program and execute this via TS.

This is an interesting way to do, but i always try to avoid creating CMD files (I prefer use VBS to Powershell), and the reason is simple….it is another script that people need to know and need to maintain. In this world where people start early using computers, creating CMD file and maintain a CMD file may not be as simples as it was when I started..anyway…

As i said, i like to avoid creating scripts and as I only want to copy files from the server to the client during the OS deployment, let’s use the robocopy. but it is not as easy as it looks…

1- we don’t want to use the wan link…let’s create a package (yes, package not application). as we’re going to create a package, we don’t need only have files, we can have folders and files (including empty folders)
2- add the package to a dp or dp group
3- on your task sequence, create a TS Variable and add the PKDID as value (this is necessary as your TS does not have a variable for it, at least as far as i know off). I called it RFLUtils_PkgID RFLUtils_PkgID
4- on your partitioning, confirm that you have a variable for the C drive. I’m using OSDisk here
5- after apply OS add “run command line step” and add the following code

robocopy.exe %_SMSTSMDataPath%\Packages\%RFLUtils_PkgID% %OSDisk%\ /e /copy:DATA /r:1 /w:1 /b /xj /xjd /xjf /log:%OSDisk%\Windows\temp\rflutils.log

The %_SMSTSMDataPath% will be converted to the pack where the package is downloaded (ie: C:\_SMSTaskSequence)
the %RFLUtils_PkgID% will be converted to the package ID (ie: 00100001)
the %OSDisk% will be converted to the drive (ie. C:\)

when the task sequence runs, the command will be converted to something like should be like

robocopy.exe C:\_SMSTaskSequence\Packages\RFL0001F C:\ /e /copy:DATA /r:1 /w:1 /b /xj /xjd /xjf /log:C:\Windows\temp\rflutils.log

6- select the package checkbox and select the package. it will make the TS download the files from the nearest DP
7- On the options select continue on error or use the following success codes: 0 3010 1 2 3 4 5 6 7 8 16
8- you are good to go

to know more about the success code, check this link http://support.microsoft.com/kb/954404

note that the error 16 is not listed but it means “Robocopy did not copy any files.  Check the command line parameters and verify that Robocopy has enough rights to write to the destination folder.”

About

Raphael is a 9 times Microsoft MVP with over 20 years of experience in IT, in which 13 years have been dedicated to System Center and Automation. His extended experience has been developed through several IT roles, from first-line support to principal consultant, towards a wide range of clients and sectors. One of the four MVPs in Enterprise Client Management in the UK, Raphael holds more than 30 Microsoft certifications and is an MCT (Microsoft Certified Trainer). Since 2008, Raphael has been providing Microsoft trainings from basic to advanced levels in several categories. Throughout his career, Raphael has joined as speaker in well-known events such as TechEd and Gartner Security Risk Management. He also organised community events and lectured around the world, sharing best practices and knowledge within the industry. Bilingual in English and Portuguese, Raphael has authored diverse articles published in Microsoft's TechEd, served as the editor-in-chief of a magazine focused on System Center in Brazil and wrote two books: "Understanding System Center 2012 SP1 Configuration Manager: The walkthrough book" and "System Center 2012 R2 Configuration Manager: Automation from Zero to Hero".

Tagged with: , , , ,