I have a powershell script to copy files from one computer to another UNC, using robocopy. Recently, it was run with a new user account, and got an Access Denied on the target. The retry limit was set to 10, so it failed out at that point. The problem is that the returns of the command do not show that there was a failure, and the exit code was 0, so the failure was not caught. Full logs below. You can see the options used at the top : (only server names changed) ( The last line is from the PS command
Write-Host "Robocopy.exe completed with code $lastexitcode")
[18:54:04][Step 1/1] Started : Monday, October 8, 2018 6:54:04 PM
[18:54:04][Step 1/1] Source : C:\Source
[18:54:04][Step 1/1] Dest : \\Server\Target
[18:54:04][Step 1/1]
[18:54:04][Step 1/1] Files : *.*
[18:54:04][Step 1/1]
[18:54:04][Step 1/1] Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /NP /R:2 /W:30
[18:54:04][Step 1/1]
[18:54:04][Step 1/1] ------------------------------------------------------------------------------
[18:54:04][Step 1/1]
[18:54:06][Step 1/1] 438 C:\Source
[18:54:06][Step 1/1] 2018/10/08 18:54:06 ERROR 5 (0x00000005) Accessing Destination Directory \\Server\Target
[18:54:06][Step 1/1] Access is denied.
[18:54:06][Step 1/1]
[18:54:38][Step 1/1] Waiting 30 seconds... Retrying...
[18:54:38][Step 1/1] 2018/10/08 18:54:38 ERROR 5 (0x00000005) Accessing Destination Directory \\Server\Target
[18:54:38][Step 1/1] Access is denied.
[18:54:38][Step 1/1]
[18:55:10][Step 1/1] Waiting 30 seconds... Retrying...
[18:55:10][Step 1/1] 2018/10/08 18:55:10 ERROR 5 (0x00000005) Accessing Destination Directory \\Server\Target
[18:55:10][Step 1/1] Access is denied.
[18:55:10][Step 1/1]
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] ERROR: RETRY LIMIT EXCEEDED.
[18:55:10][Step 1/1]
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] ------------------------------------------------------------------------------
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] Total Copied Skipped Mismatch FAILED Extras
[18:55:10][Step 1/1] Dirs : 1 0 1 0 0 0
[18:55:10][Step 1/1] Files : 0 0 0 0 0 0
[18:55:10][Step 1/1] Bytes : 0 0 0 0 0 0
[18:55:10][Step 1/1] Times : 0:01:06 0:00:00 0:01:00 0:00:06
[18:55:10][Step 1/1] Ended : Monday, October 8, 2018 6:55:10 PM
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] Robocopy.exe completed with code 0
My only hunch even at this point is that there is something strange about the specific error "Accessing Destination Directory". When I try a test simply removing file permissions, I get the error
14:08:15 ERROR 5 (0x00000005) Copying File
and robocopy correctly returns exit code 8, with FAILED count = 1.
TIA
JS
robocopy is a cmd executable, and will not return a $false to powershell, if that's what you're looking for. a good example is the ping command always returns an exit code of 0. You'll need to utilize a powershell command. copy-item is a good start.
If you must MUST use robocopy, then you could put it into a variable, and have the response checked for "access denied" etc.. in the string. not sure what your code is, or what you're copying... but an idea...
$temp = robocopy *.* /s... etc...
if ($temp -match "Access is denied"){"Robocopy failed due to a denial of access"}
User contributions licensed under CC BY-SA 3.0