Robocopy Light

by Aug 28, 2017

Robocopy.exe is an extremely powerful and versatile built-in command to copy files efficiently from one location to another. Unfortunately, this command has so many options and switches that very often make it hard to use.

If all you want is to copy files from A to B, here is a simple PowerShell function that wraps robocopy and turns the beast into a simple-to-use copy command:

function Copy-FileWithRobocopy
{
    param
    (
        [Parameter(Mandatory)]
        $Source,

        [Parameter(Mandatory)]
        $Destination,
        
        $Filter = '*'
    )

    robocopy.exe $Source $Destination $Filter /S /R:0 
}

Here is how you’d use the new command: the next line copies all .log files from the Windows folder into a new folder called c:\logs:

 
PS> Copy-FileWithRobocopy -Source $env:windir -Destination c:\logs -Filter *.log
 

Twitter This Tip! ReTweet this Tip!