How to pass parameters with spaces as a RoboCopy array to Powershell?

I am working on a script that requires RoboCopy switches to be passed dynamically based on user input, so using arrayseems like the best option. However, when used, I specify the following parameters: /XFwhich have a space and a value.

It works as expected:

RoboCopy C:\Dir1 C:\Dir2 /NP /NFL /NS /NDL /NJH /NJS /XF *.config

It works as expected:

$Switches = @("/NP", "/NFL", "/NS", "/NDL", "/NJH", "/NJS", "/E")

RoboCopy C:\Dir1 C:\Dir2 $Switches

This causes ERROR : Invalid Parameter #10 : "/XF *.config":

$Switches = @("/NP", "/NFL", "/NS", "/NDL", "/NJH", "/NJS", "/E", "/XF *.config")

RoboCopy C:\Dir1 C:\Dir2 $Switches

I tried several things, such as using quotation marks with a parameter /XF, but without success. Any hints / help are appreciated.

+5
source share
2 answers

Can you try this, I can not check it, but let me know ..:

$Switches = @("/NP", "/NFL", "/NS", "/NDL", "/NJH", "/NJS", "/E", "/XF", "*.config")
+4
source

My option (more XD / XF options):

$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
+2
source

All Articles