I'm attempting to use robocopy in a PowerShell script, but currently failing. When I run the following command manually
robocopy \\corporatesystem00.local.com\C$\Maven\ \\corporatesystem01.local.com\C$\Maven\ * /e /purge
I am able to copy all the contents of one folder to another, and it works like magic. However, with how "wonderful" PowerShell is, I think I'm running into an unknown gotchya. When I run the same command above from a PowerShell script, I receive this error:
PS C:\Program_Files> .\jenkins-maven-copy.ps1
Performing Jenkins Maven Sync
robocopy \\corporatesystem00.local.com\C$\Maven\ \\corporatesystem01.local.com\C$\Maven\ * /e /purge
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Wednesday, July 30, 2014 3:00:03 PM
Source - \\corporatesystem00.local.com\C$\Maven\
Dest - \\corporatesystem01.local.com\C$\Maven\
Files : *
Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
ERROR : Invalid Parameter #4 : "/e /purge"
Simple Usage :: ROBOCOPY source destination /MIR
source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
/MIR :: Mirror a complete directory tree.
For more usage information run ROBOCOPY /?
**** /MIR can DELETE files as well as copy them !
This happens for any commandline option I'm putting in for my options in the script. The script I am running, is below.
Param (
[string]$srcLocation = '\\corporatesystem00.local.com\C$\Maven\',
[string]$destLocation = '\\corporatesystem01.local.com\C$\Maven\',
[string]$files = '*',
[string]$options = '/e /purge'
)
function syncMaven( $srcLocation, $destLocation, $files, $options )
{
Write-Host "Performing Jenkins Maven Sync"
Write-Host "robocopy $srcLocation $destLocation $files $options"
robocopy $srcLocation $destLocation $files $options
}
syncMaven $srcLocation $destLocation $files $options
If you look at the error/output from earlier, it shows that the command is being passed, with the command options, but robocopy isn't recognizing them or something.
PS C:\Program_Files> .\jenkins-maven-copy.ps1
Performing Jenkins Maven Sync
robocopy \\corporatesystem00.local.com\C$\Maven\ \\corporatesystem01.local.com\C$\Maven\ * /e /purge
So, I'm at a loss.