Azure file share Robocopy batch file scripting 0 Reputation points


I'm trying to write a windows batch script for robocopying one azure file share to another on every midnight.

I succeed to run below command manually by executing on powershell, but it always fail with batch file using Task scheduler.

I tried cmd.exe to add credentials and also tried net use for input the user and password but it doesn't work.

Can anyone give me some advice?

Batch Script



robocopy "\\attachment" "\\attachment" /mt /E /mir /COPYALL /ZB /r:2 /w:1 /LOG+:C:\Users\gw_admin\Desktop\RobocopyBackup_mir.log

#msg * "==%date% %time% Robocpy sync Complete=="



Log Errors


   ROBOCOPY     ::     Robust File Copy for Windows                              

  Started : 2023 10 17   1:53:44
   Source = \\\attachment\
     Dest = \\\attachment\

    Files : *.*
  Options : *.* /S /E /COPYALL /PURGE /MIR /ZB /IM /MT:8 /R:2 /W:1 


NOTE : Security may not be copied - Destination might not support persistent ACLs.

2023/10/17 13:53:44 ERROR 1326 (0x0000052E) Creating Destination Directory \\\attachment\
The user name or password is incorrect.
Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,175 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Thomas Hartl 75 Reputation points


    to copy files between Azure file shares I'd recommend using the tool "azcopy". Depending on the configuration and size of your Azure file shares, you could use "azcopy sync" or "azcopy copy" (if you need to use --delete-destination on large file shares), using SAS authentication.

    The following example would copy all changed files, based on their "last modified" date, from the source to the destination directory and remove files that no longer exist in the source directory:

    azcopy sync 'https://<source-storage-account-name><SAS-token>' 'https://<destination-storage-account-name><SAS-token>' --recursive --delete-destination=true

    You can find further examples in Microsofts AzCopy documentation: Use AzCopy with Files > Synchronize files