Simple RoboCopy Function for quick transfers

A couple of weeks ago I got to thinking, I do these little robocopy transfers all the time why not write a function so I can do a transfer and I don’t have to go looking up all the parameters.  So after a few minutes, the below script was born.  Simply run the script in Powershell, and it will prompt for the old folder (source) and the new folder (destination).  Once the copy is complete it will monitor the source directory and copy any changes until you exit the script which is great when a user is still working in the source directory such as when you need to move a home directory.  It also sticks a log file in the directory you ran the script.  Just keep in mind that this is setup to be a mirror copy and if you reverse the source and destination you will copy the blank destination to your source and end up with a blank directory.

It’s an extremely simple script but maybe it will save someone a little time.  Also in case you haven’t aren’t familiar with robocopy it is the best folder syncing tool out there and has been available since Windows Server 2003.  It won’t sync single files but will sync folders up wherever you need them, resume transfers where they left off on flaky network connections, allows throttling and much more.

function fun-robocopy {
$ScriptPath = (Get-Item -Path ".\" -Verbose).FullName
$Logfile = $ScriptPath+"\Robocopy Logfile.log"
$OLDFolder = Read-Host -Prompt 'Input Old folder to move'
$NewFolder = Read-Host -Prompt 'Input New folder to move to'
Robocopy $OldFolder $NewFolder /MIR /COPYALL /V /FP /XO /LOG+:$Logfile /TEE /Z /MON:1 /MOT:30 /W:5 /R:2
}
fun-robocopy
snip_20160531170841

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s