$robocopy = ("$env:SystemRoot\System32\robocopy.exe ") $source = '"\\MYSERVER\netlogon\MyFolder\MyStuff" ' $destination = '"C:\MyFolder\MyStuff" ' $options = "/MIR R:1 W:1 /XJ " $excFiles = '/XF "test.txt" today.doc" ' $excDirs = '/XD "test" "today" ' $log = '/NFL /NDL /LOG:"C:\mycopy.log"' Write-Host "------------------------------------" $robocopy $source $destination $options $excFiles $excDirs $log Write-Host "------------------------------------" $command = $robocopy+$source+$destination+$options+$excFiles+$excDirs+$log $command Invoke-Command $command
------------------------------------
C:\Windows\System32\robocopy.exe
"\\US0TE0DC0A01\netlogon\MyFolder\MyStuff"
"C:\MyFolder\MyStuff"
/MIR R:1 W:1 /XJ
/XF "test.txt" today.doc"
/XD "test" "today"
/NFL /NDL /LOG:"C:\mycopy.log"
------------------------------------
C:\Windows\System32\robocopy.exe "\\MYSERVER\netlogon\MyFolder\MyStuff" "C:\MyFolder\MyStuff" /MIR R:1 W:1 /XJ /XF "test.txt" today.doc" /XD "test" "today" /NFL /NDL /LOG:"C:\my
copy.log"
Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
At C:\invokeRobocopy.ps1:20 char:1
+ Invoke-Command $command
+ ~~~~~~~~~~~~~~~~~~
The command appears to be quoted properly for execution on the command line.
How do I format these multiple parameters for Invoke-Command?