How to use robocopy to copy directories on different domains [closed]

I want to copy a directory(abc) from domain1/user1 to domain2/user1. any idea how to do this. e.g robocopy

robocopy \\server1\G$\testdir\%3 \\server2\g$\uploads

and both are on different domains


Solution 1:

Robocopy will use the standard windows authentication mechanism.

So you probably need to connect to the servers using the appropriate credentials before you issue the robocopy command.

You can use net use to do this and you could put that in a batch script.

Note that Windows doesn't like you to connect to the same server with two different sets of credentials (so you can't copy from and to the same server as different users). But that's not what it looks like you need.

Something like this:

net use \\server1\g$ /user:domain1\user1 * 
net use \\server2\g$ /user:domain2\user2 *
robocopy \\server1\G$\testdir\%3 \\server2\g$\uploads

Notes:

  • This is using 'deviceless' connections which will not be recreated at start up (and won't appear with a drive letter in windows explorer).
  • The asterisk at the end of the net use command means prompt for password, you could hard code the password in there (or get it as a parameter to the script).
  • Might be worth reading up on net use to make sure it does what you need.

You can probably also remove the network connection to the servers by using this (I haven't tried this with a deviceless connection):

net use \\server1\g$ /delete
net use \\server2\g$ /delete