Powershell + Robocopy

I know this is not strictly a powershell topic, but I am trying to use a powershell script to check for existence of files, and then if they don’t exist copy them from a network location to the current users %appdata% subdirectories
I have listed the code below and the error I am getting, I have tried multiple variations of this code.
Your assistance is greatly appreciated.

If (test-path $env:APPDATA"\microsoft\signatures\citywide signature.txt") {exit}
$source= “\addomainname\SYSVOL\deerpark.local\scripts\Citywide Signature”
$Destination= $env:APPDATA + “\microsoft\signatures”
$options= ("/r:5","/w:10","/e")
invoke-expression “robocopy $source $destination $options”


ROBOCOPY :: Robust File Copy for Windows

Started : Tuesday, January 17, 2017 11:39:14 AM
Source - \deerpark.local\SYSVOL\deerpark.local\scripts\Citywide
Dest - C:\Users\ahollister\downloads\Citywide Signature\Signature\

Files : 

Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30


ERROR : Invalid Parameter #3 : “C:\Users\ahollister\AppData\Roaming\microsoft\signatures”

No need for Invoke-Expression and a double quotation was in the wrong place.

$source= "\\addomainname\SYSVOL\deerpark.local\scripts\Citywide Signature\"
$Destination= "$env:APPDATA\microsoft\signatures\"

If (-NOT(test-path "$env:APPDATA\microsoft\signatures\citywide signature.txt")) {
    robocopy $Source $Destination "/r:5","/w:10","/e"
} Else {Write-Verbose "File exists for $env:USERNAME" -Verbose}

using your method, I now see this error…

Started : Tuesday, January 17, 2017 12:49:48 PM
Source : \deerpark.local\SYSVOL\deerpark.local\scripts\Citywide Signature" C:\Users\ahollister\AppData\Roaming\microsoft\signatures\ \r:5,\w:10,\e
Dest -
Files : .
Options : . /DCOPY:DA /COPY:DAT /R:1000000 /W:30

ERROR : No Destination Directory Specified.

the best method I found for robocoopy is:

$source= "\\addomainname\SYSVOL\deerpark.local\scripts\Citywide Signature\"
$Destination= $env:APPDATA + "\microsoft\signatures\"
$options= $source, $destination, "/r:5","/w:10","/e"

& robocopy $options

shows the whole string as the source


ROBOCOPY :: Robust File Copy for Windows

Started : Wednesday, January 18, 2017 9:28:49 AM
Source : \deerpark.local\SYSVOL\deerpark.local\scripts\Citywide Signature" C:\Users\ahollister\AppData\Roaming\microsoft\signatures\ \r:5 \w:10 \e
Dest -

Files : *.*

Options : . /DCOPY:DA /COPY:DAT /R:1000000 /W:30


ERROR : No Destination Directory Specified.

I think you forget a comma or a quote between $source and $destination.
why you don’t post command executed, just result ? I haven’t a crystal ball :slight_smile:

PS C:\> $source= 'C:\111'
PS C:\> $Destination= 'C:\222'
PS C:\> $options= $source, $Destination, "/r:5", "/w:10", "/e"
PS C:\> & robocopy $options

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Thu Jan 19 11:06:44 2017

   Source : C:\111\
     Dest : C:\222\

    Files : *.*

  Options : *.* /S /E /COPY:DAT /R:5 /W:10

------------------------------------------------------------------------------

                           3    C:\111\
100%        New File                 233        disableIPV6.bat
100%        New File              931933        DynDNS.log
100%        New File               60617        log

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         3         3         0         0         0         0
   Bytes :   969.5 k   969.5 k         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00


   Speed :            62048937 Bytes/sec.
   Speed :            3550.468 MegaBytes/min.

   Ended : Thu Jan 19 11:06:44 2017

NetAdminTX,

are you running this on Windows 10 build 14393 (Anniversary Update) or 14986? I’ve done some testing with above code and it looks like the PowerShell engine in both builds and may be later versions too is passing everything as one argument to robocopy instead of separate arguments. It works for me as expected on Windows 7 with PSVersion 5.0.10586.117 which is an older PS engine.

Yep that appears to be the problem.
I apologize for the late response.

I worked around this problem by using copy-item as opposed to calling robocopy
I don’t know if there is any performance difference, but even if there is it will not make a large difference on 25MB of files.

thanks for your help everyone.