Add authentication to access remote files while using robocopy

Hi All! Most of system administrators knows about robocopy or have been using the same to copy files from one location to another. It’s a very robust tool which would keep the permission and timestamp intact while copying the files. There are many more features which you can explore as per your use case, if you haven’t use this tools until now, you can read more about this tool here

One thing which i observed that robocopy don’t have any in-built feature to access the files which require some type of authentication. For example, if the source location files are lying on domain A server and you want to copy the files to domain B server which is the destination location and you are running the script from same domain, in this case, you need to provide a different credential in order to access the files from domain A.

To work around this issue you can open an IPC$ connection to source location by using net use command. IPC$ share is also known as a null session connection. Below is the script which we used to access the remote file by doing and authentication –

$IPCServer = “SourceServerName”
$IPCUser = “domain\user”
$IPCPass = “Password”
$sourceDir = “SourceLocation_UNC_Path”
$destinationDir = “Destination_UNC_Path”
#Create the IPC$ connection
net use “\\$IPCHost\IPC$” /u:$IPCUser $IPCPass
robocopy $sourceDir $destinationDir /s /r:2 /w:2 /xo
#to delete the IPC$ connectoin
net use “\\$IPCHost\IPC$” /D

That’s all for today, let me know if you observed any issue while using robocopy.

One thought on “Add authentication to access remote files while using robocopy

Leave a comment