Functions/Copy-WithRobocopy.ps1


function Copy-WithRobocopy {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)] [string] $Source,
        [Parameter(Mandatory)] [string] $Destination,
        [Parameter()] [switch] $Force
    )



    $Source = (Get-Item $Source).FullName
    if ($Source[($Source.Length - 1)] -eq "\") {
        $Source = $Source.Substring(0, ($Source.Length - 1))
    }


    if ($Destination[($Destination.Length - 1)] -eq "\") {
        $Destination = $Destination.Substring(0, ($Destination.Length - 1))
    }




    $Source
    $Destination


    if (Test-Path $Source) {
        if (Test-Path $Destination -and !($Force)) {
            Write-Warning "$($Destination) already exists"
        } else {
            robocopy "$Source" "$Destination" /MIR /W:1 /R:1
        }
    } else {
        Write-Warning "$($Source) does not exist"
    }


}