This post will cover how to copy all the contents of a folder one one server (server1) and copy it to another folder a different server (server2). It will also make sure that the NTFS permission will stay intact.
One server1 make sure that you have robocopy in the same folder as the script or in the Windows path. In my case I put it in the C:\Windows\system32 directory. You can download robocopy from here.
This script will make sure that there is no pre-existing mapped drive. It will connect to server2 and map z: to the share we want to copy. It will then call robocopy and move all data from itself to the external server share. The “/sec” switch is key for retaining the security of the file permission. The script will create a log file that you can check things after you are done.
net use z: /deletenet use z: \\server2\datarobocopy.exe C:\data\ z:\ /sec /S /XO /R:3 /W:5 /LOG:C:\MANAGEMENT\LOGS\robocopy.txt
Hope you enjoyed this post on how to sync two folders and copy the NTFS permissions with robocopy.