How to pass parameters with spaces as an array to RoboCopy in Powershell?
powershell, robocopy
Solution
Can you try this, I can't test it but let me know..:
$Switches = @("/NP", "/NFL", "/NS", "/NDL", "/NJH", "/NJS", "/E", "/XF", "*.config")
Problem
I am working on a script that needs RoboCopy switches to be passed in dynamically based on user input, hence using `array` seems like the best option. However I see the following issue when using I specify parameters like `/XF` that have a space and value. This works as expected: ``` RoboCopy C:\Dir1 C:\Dir2 /NP /NFL /NS /NDL /NJH /NJS /XF *.config ``` This works as expected: ``` $Switches = @("/NP", "/NFL", "/NS", "/NDL", "/NJH", "/NJS", "/E") RoboCopy C:\Dir1 C:\Dir2 $Switches ``` This throws `ERROR : Invalid Parameter #10 : "/XF *.config"`: ``` $Switches = @("/NP", "/NFL", "/NS", "/NDL", "/NJH", "/NJS", "/E", "/XF *.config") RoboCopy C:\Dir1 C:\Dir2 $Switches ``` I tried few things like using quotes with `/XF` parameter but no success. Any hint/help is appreciated.