Powershell Script to start a lot of Robocopy Jobs

 We were recently helping a customer with a domain consolidation where we had to copy a bunch of files from several different domains over to a new file server.  We decided to break the task up into a few steps, the first of which was to simply get the data onto the destination!  To do that, we decided to use Robocopy, but we were going to need to copy data from several different domains without trust relationships, meaning that we'd have to get a bit creative with gaining access to the source data.

In the end, I put together a script!  This guy takes several important input parameters: foldersList, drivesList, and logFolder.

FoldersList is the path to a CSV that lists all of the folders that are being migrated.  This script ultimately depends on two columns in that CSV: SourceDrive and DestinationDrive, although we put SourceUNC and DesintationUNC fields in that file to help with later steps.  At its core, the FoldersList CSV is used to make the robocopy commands, defining the source and the destination for each command.  The interesting challenge here was figuring out how to deal with getting access to the various sources.

We did that with the drivesList csv file.  It needs three columns: DriveLetter, UNCPath, and Credentials.  We decided that the best way for us to give Robocopy the permissions that it needed was to map those source shares, so that we could specify appropriate accounts for each one.  For each drive share, that file needs a letter to use when mapping it, the UNC path of the share to map, and a path to a secured powershell credential object (as an XML file).  You probably don't have that last thing already built the first time you run the script, so if it can't find the file where it's been specified, it will prompt the operator for credentials and then save them to that file.

Once it has all of the drives mapped, it then goes through and kicks off a robocopy command for each folder specified in the foldersList csv!  We set the script to store robocopy logs in the folder specified by the logFolder parameter, but we quickly realized that those log files were difficult to use.  So, I built a little log parser at the bottom that goes through that file and gives the operator a set of grand totals for all of the robocopy jobs, highlighting errors in that summary file.  If there's something mysterious there, that should make it easier to find the exact error in the main log file.

And that's it!  We put together a few other scripts to read all of the NTFS permissions on the source side (and the groups that are used in those permissions) and then recreate those structures in the destination... but those are each quite complicated and so are topics for another time!

Check out the script on Github!

Comments

Popular posts from this blog

Clone a Standard vSwitch from one ESXi Host to Another

PowerShell Sorting by Multiple Columns

Deleting Orphaned (AKA Zombie) VMDK Files