none
Robocopy Error 3 (System cannot find path specified) and Error 5 (Access Denied)?

    Question

  • So I am really new to Powershell and just yesterday learned about Robocopy.

    I have been trying to find a solution to this problem:

    I wrote a script in Powershell that is to simulate a "Backup". It  should copy files, using Robocopy, from user specified folders on a server to a user specified location elsewhere.

    Right now, I have been testing it various ways.

    1) One way I tried testing it was mapping the server's location as a network drive. I currently have it as drive V:\.
    Whenever I run the script, I get this error:

    Get-Item: Cannot find drive. A drive with the name 'V' does not exist.
    ERROR 3 (0x00000003) Accessing Source Directory V:\
    The System cannot find the path specified.

    I'm using Robocopy like this: robocopy $spath $newFolder /COPY:DAT /b

    2) The first time I tried test my script, I was trying to access directly to the server. $spath = \\###.###.##.###\
    Whenver I tried this, this is the error I got:

    Get-Item : Cannot find path '\\###.###.##.###\' because it does not exist.
    ERROR 5 (0x00000005) Accessing Source Directory \\###.###.##.##\
    Access is denied.


    I am running Powershell as an administrator, on the administrator account on this computer (It's just for testing, but it's a Windows 7 desktop).
    Any ideas?


    Edit: The destination path is a hard drive that we have connected USB 2.0
    • Edited by Cattzs Friday, June 29, 2012 2:22 PM
    Friday, June 29, 2012 2:21 PM

Answers

  • Honestly not sure why it's not working for you.. I thought it might be something to do with the hidden share so I tried that and still couldn't reproduce the problem.

    judging by your screenshot you're calling your script with a parameter for the file containing the source path so i wrote some .xml files to get the source and dest path from and it still worked o_O so i'm outta ideas!

    the below works perfectly here if thats any help.

    contents of testsourcelist.xml (i know it's not a valid xml file but i was feeling lazy)

    <sourcePath>\\192.168.1.1\media0$\</sourcePath>
    

    contents of testdestlist.xml

    <destPath>c:\hello</destPath>

    contents of test2.ps1

    $sourcelist_filename=$args[0]
    [xml]$sourcelist = Get-Content $sourcelist_filename
    [xml]$destlist = Get-Content testdestlist.xml
    
    $spath = $sourcelist.sourcePath
    $dpath = $destlist.destPath
    $today = Get-Date
    $name = "test"
    $newName = $name + $today.month +$today.day + $today.year
    $newFolder = $dpath + '\' +$newName
    robocopy $spath $newFolder /COPY:DAT /b

    command used..

    .\test2.ps1 .\testsourcelist.xml

    output..

    -------------------------------------------------------------------------------
       ROBOCOPY     ::     Robust File Copy for Windows
    -------------------------------------------------------------------------------
    
      Started : Fri Jun 29 19:53:44 2012
    
       Source : \\192.168.1.1\media0$\
         Dest : c:\hello\test6292012\
    
        Files : *.*
    
      Options : *.* /COPY:DAT /B /R:1000000 /W:30
    
    ------------------------------------------------------------------------------
    
                               3    \\192.168.1.1\media0$\
    
    ------------------------------------------------------------------------------
    
                   Total    Copied   Skipped  Mismatch    FAILED    Extras
        Dirs :         1         0         1         0         0         0
       Files :         3         0         3         0         0         0
       Bytes :     2.5 k         0     2.5 k         0         0         0
       Times :   0:00:00   0:00:00                       0:00:00   0:00:00
    
       Ended : Fri Jun 29 19:53:44 2012

    works absolutely fine here :(

    • Marked as answer by Cattzs Monday, July 2, 2012 4:05 PM
    Friday, June 29, 2012 6:57 PM

All replies

  • The path in your example is just the computer name/ip address.. are you specifying a share at the end too?

    ie. \\192.168.1.1\sourceshare

    and if so, can you browse to that share by simply clicking on start->run and entering \\192.168.1.1\sourceshare

    We'd probably be able to give you a better idea if you pasted the snippet of actual code (i.e you're using 'Get-Item' somewhere - we need to see the context to understand exactly what you're doing before you're invoking robocopy)

    Friday, June 29, 2012 3:09 PM
  • Oh, yeah I am. And yes, I can get to the share. Sorry. I'll post some code:

    So I have the script reading an XML file for the source and destination and other info:

    <sourcePath>\\130.207.53.219\Backup$\WindowsImageBackup\</sourcePath>
    <destinationPath>G:\FileServer</destinationPath>

    I have that XML file read in and assigns each as it should (I'm leaving out some bits of code, the bits work and I don't think are very relevant):

    $spath =$backup.sourcePath
    $dpath = $backup.destinationPath
    And here is where I get the error, at the Get-Item
    $moveThis = Get-Item $spath
    $today = Get-Date
    $newName = $name + $today.month +$today.day + $today.year
    $newFolder = $dpath + '\' +$newName
    robocopy $spath $newFolder /COPY:DAT /b

    And it causes the robocopy to error.


    • Edited by Cattzs Friday, June 29, 2012 3:30 PM
    Friday, June 29, 2012 3:30 PM
  • Odd! If I do the following it works perfectly and copies the contents of \\192.168.6.2\media0 to a folder called c:\hello\test6292012

    $spath = "\\192.168.1.1\media0"
    $dpath = "c:\hello"
    $today = Get-Date
    $name = "test"
    $newName = $name + $today.month +$today.day + $today.year
    $newFolder = $dpath + '\' +$newName
    robocopy $spath $newFolder /COPY:DAT /b

    With that in mind, it sounds like robocopy doesn't like whatever method you're using for getting the sourcepath into a string? Or maybe you'll need to use quotes around your $spath in the robocopy line?

    Work backwards and before the robocopy perhaps put a..

    write-host "$spath"

    ..to make sure the $spath is definitely defined properly?

    Friday, June 29, 2012 4:16 PM
  • I have a Write-Host every few lines. That's how I initially figured out what was going on..

    Here's what Powershell shows after running my script: Image



    • Edited by Cattzs Friday, June 29, 2012 6:33 PM
    Friday, June 29, 2012 6:30 PM
  • Honestly not sure why it's not working for you.. I thought it might be something to do with the hidden share so I tried that and still couldn't reproduce the problem.

    judging by your screenshot you're calling your script with a parameter for the file containing the source path so i wrote some .xml files to get the source and dest path from and it still worked o_O so i'm outta ideas!

    the below works perfectly here if thats any help.

    contents of testsourcelist.xml (i know it's not a valid xml file but i was feeling lazy)

    <sourcePath>\\192.168.1.1\media0$\</sourcePath>
    

    contents of testdestlist.xml

    <destPath>c:\hello</destPath>

    contents of test2.ps1

    $sourcelist_filename=$args[0]
    [xml]$sourcelist = Get-Content $sourcelist_filename
    [xml]$destlist = Get-Content testdestlist.xml
    
    $spath = $sourcelist.sourcePath
    $dpath = $destlist.destPath
    $today = Get-Date
    $name = "test"
    $newName = $name + $today.month +$today.day + $today.year
    $newFolder = $dpath + '\' +$newName
    robocopy $spath $newFolder /COPY:DAT /b

    command used..

    .\test2.ps1 .\testsourcelist.xml

    output..

    -------------------------------------------------------------------------------
       ROBOCOPY     ::     Robust File Copy for Windows
    -------------------------------------------------------------------------------
    
      Started : Fri Jun 29 19:53:44 2012
    
       Source : \\192.168.1.1\media0$\
         Dest : c:\hello\test6292012\
    
        Files : *.*
    
      Options : *.* /COPY:DAT /B /R:1000000 /W:30
    
    ------------------------------------------------------------------------------
    
                               3    \\192.168.1.1\media0$\
    
    ------------------------------------------------------------------------------
    
                   Total    Copied   Skipped  Mismatch    FAILED    Extras
        Dirs :         1         0         1         0         0         0
       Files :         3         0         3         0         0         0
       Bytes :     2.5 k         0     2.5 k         0         0         0
       Times :   0:00:00   0:00:00                       0:00:00   0:00:00
    
       Ended : Fri Jun 29 19:53:44 2012

    works absolutely fine here :(

    • Marked as answer by Cattzs Monday, July 2, 2012 4:05 PM
    Friday, June 29, 2012 6:57 PM
  • Well that is very perplexing... darn. Well thanks for your help!
    Monday, July 2, 2012 3:57 PM
  • I would first test robocopy in a cmd prompt to make sure its not a problem
    with access or something else...
     
    are you running this from a sched task?
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, July 2, 2012 4:10 PM
  • Hm. Thank you for trying to help, but my script apparently only works on a machine with all privileges.  I was just working on a test machine, but the script works fine on my boss's machine.

    We have some strange rules and group policy security and junk here.

    Thanks for all your help, everyone!

    Thursday, July 5, 2012 1:23 PM
  • I have just been able to replicate the issue.

    In my case, reason was fairly simple. I have been using old version of robocopy.

    Once I have removed old version of robocopy from my script folder, system automaticaly used latest version and everything works fine now ;)

    Hope this will help

    Tuesday, November 5, 2013 2:02 PM
  • This is caused by running with highest privileges(on the local system).  Please run as the user not as administrator.  Normally the administrator only has local access, no access to the server. 

     

    Dan

    • Proposed as answer by vdan02 Thursday, December 5, 2013 3:54 PM
    Thursday, December 5, 2013 3:54 PM
  • Dan, your answer is correct.  I just replicated the same problem, and your answer fixed it.  Thank you!
    Friday, December 6, 2013 6:51 PM
  • This is caused by running with highest privileges(on the local system).  Please run as the user not as administrator.  Normally the administrator only has local access, no access to the server. 

     

    Dan

    Great find thanks Dan.
    Thursday, March 2, 2017 11:39 PM
  • Worked for me!  Thanks, Dan
    Tuesday, October 10, 2017 4:40 PM
  • Please do not reactivate ancient threads. Especially if you can't contribute anything new or helpful.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Tuesday, October 10, 2017 6:07 PM
  • Please do not reactivate ancient threads. Especially if you can't contribute anything new or helpful.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Tuesday, October 10, 2017 6:07 PM