Skip to content

Instantly share code, notes, and snippets.

@FooBartn
Created September 2, 2016 23:50
Show Gist options
  • Save FooBartn/af4e14db6c7701e623263b1a7a41782b to your computer and use it in GitHub Desktop.
Save FooBartn/af4e14db6c7701e623263b1a7a41782b to your computer and use it in GitHub Desktop.
function Invoke-Robocopy () {
[cmdletbinding()]
param (
# Copy from location
[Parameter(Mandatory=$true)]
[string]
$Path,
# Copy to location
[Parameter(Mandatory=$true)]
$Destination,
# List of arguments to be splatted to ROBOCOPY
[Parameter(Mandatory=$true)]
[array]
$ArgumentList
)
ROBOCOPY.exe $Path $Destination @ArgumentList
switch ($LastExitCode) {
0 { Write-Verbose 'No files copied. Source and destination are in sync' }
1 { Write-Verbose 'Files were copied successfully'}
2 { Write-Verbose 'Extra files/directories detected. Housekeeping may be required.'}
4 { Write-Verbose 'Mismatched files/directories detected. Housekeeping may be required.'}
8 { Write-Error 'Some files/directories could not be copied'}
10 { Write-Error 'Usage error or an error due to insufficient access privileges'}
}
exit ($LastExitCode -band 24)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment