In my job as a Systems Administrator I find myself copying files quite often. Usually this happens from my laptop which connects to our VPN and my home drive on the company network. To simplify this process, since the destination doesn’t change much, I have mixed PowerShell and Robocopy.
This is not new… nor is it rocket science, but it is pretty handy regardless. The PowerShell script/function/module (choose whichever) creates variables for the source, destination, and stuff to be copied and passes these to Robocopy which does the lifting.
A simple example of a function is below:
[string]$destination = “\\server.domain.com\myhomedirectory”,
[string]$options = “/R:0″,”/W:0″,”/COPY:DAT”)
robocopy $source $destination $stuff $options
Now keep in mind there should probably be some error checking done, which could simply check for a return code of 0 from Robocopy and end if true or write to the command line or whatever. If I come up with a reason to evolve this beyond the simple move this from here to there, maybe I will add it. For now though… this little function is awesome.
To execute it, call the powershell function and pass your values in. Robocopy will do the rest and display the usual output summary when completed.