Just a quick function I knocked up to copy files via RoboCopy in powershell. If the destination directory does not exist, the function will create it. Use at your own risk.
function Copy-RoboCopy{
[cmdletbinding()]
param(
[Parameter(Mandatory)]
[ValidateScript({[System.IO.Directory]::Exists($_);})]
[string]$SourceDir,
[Parameter(Mandatory)]
[string]$Destination
)
begin{
}
process{
if(!(Test-Path $Destination -PathType Container)){
New-Item -ItemType Directory -Path $Destination -Force
}
if(!(test-path -Path "C:\Windows\System32\robocopy.exe" -PathType Leaf)){
throw "Robocopy is not installed."
}
robocopy "$SourceDir" "$Destination" *.* /S /MT:32 /XJ /R:25 /W:5 /NP /XX
}
end{
}
}
Leave a comment