Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters with spaces as an array to RoboCopy in Powershell?

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.

like image 683
Nitin Badole Avatar asked Apr 04 '13 11:04

Nitin Badole


2 Answers

Can you try this, I can't test it but let me know..:

$Switches = @("/NP", "/NFL", "/NS", "/NDL", "/NJH", "/NJS", "/E", "/XF", "*.config")
like image 109
CB. Avatar answered Nov 10 '22 12:11

CB.


My variant (more XD/XF parameters):

$RobocopyParams = @("/NP", "/NFL", "/NS", "/NDL", "/NJH", "/NJS", "/E")
$XD = @("Cookies", "His6", "SendTo", "Temp", "Temporary Internet Files", "Windows")
$XF = @("*.pif", "$UserName.INI", "$UserName.OPS", "$UserName.INI.*")
robocopy.exe @params /XD @XD /XF @XF
like image 39
MKesper Avatar answered Nov 10 '22 10:11

MKesper