dsccommunity / xRobocopy

DSC Module to automate Robocopy transfers
MIT License
54 stars 15 forks source link

Not splatting properly for ExcludeDirs and ExcludeFiles on Dev branch #19

Open gerane opened 8 years ago

gerane commented 8 years ago

These two params are not working properly. If excluding multiple Files or Directories it thinks they are a single file.

if ($ExcludeFiles) 
    {
        $arguments += @('/XF', $ExcludeFiles)
    }
    if ($ExcludeDirs) 
    {
        $arguments += @('/XD', $ExcludeDirs)
    }

Exclude Directories is actually missing from the parameters as well, so it is being checked for, but not actually available.

Currently, when robocopy runs, the output looks like this

Exclude Dirs

Files : *.*

Exc Dirs : Files Private

Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1000000 /W:30 

Exclude Files

Files : *.*

Exc Files : Invoke-test.ps1xml Test-*

Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1000000 /W:30

The files should be on separate lines line the following output.

Exclude Dirs

Files : *.*

Exc Dirs : Files
           Private

Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1000000 /W:30

Exclude Files

Files : *.*

Exc Files : Invoke-test.format.ps1xml
            Test-*

Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1000000 /W:30

One way you could handle this is to take ExcludeFolders and ExcludeFiles as arrays, and then add them to the arguments like this.

    if ($ExcludeFiles) 
    {
        $arguments += '/XF'
        $arguments += $ExcludeFiles
    }
    if ($ExcludeDirs) 
    {
        $arguments += '/XD'
        $arguments += $ExcludeDirs
    }

Then even if the files or folders have spaces in their names it works without issue.

An Example when passing arrays:

Files : *.*

Exc Files : Invoke-test.format.ps1xml
             Test-*

Exc Dirs : Files
            Private with spaces

Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1000000 /W:30
narrieta commented 8 years ago

@gerane: thank you for reporting this issue

narrieta commented 8 years ago

Actual bug; closed by mistake so reopening

Arturas-K commented 8 years ago

Hi,

You can use AditionalArgs array to workaround this. I have added some samples in #23;