Call RoboCopy via Powershell

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.