I have worked on some repetitive works which involves copying files between some servers. I always try to automate as it reduce the manual errors and I am lazy to do boring task in manual :).
Copy-Item is simple and straight forward. But Robocopy provides more features. It provides many options like retry/jobs/filtering/mirroring which I use mostly when working.
We can get the all supported parameters from Robocopy documentation or simple running
robocopy /? in command line.
$source = '<SOURCE_PATH>' $destination = '<DESTINATION_PATH>' # /E - Copies subdirectories. This option automatically includes empty directories. Refer the doc for supported parameters $robocopyOptions = @('/E') Write-Host 'Copying from $source to $destination' $CmdLine = @($source, $destination) + $robocopyOptions & 'robocopy.exe' $CmdLine Write-Host 'Copy Completed'
Preceding command invokes Robocopy windows utility and copy the files. This is the simplest usage and we can use it for more complex scenarios.