Home > Scripting > ROBOCOPY network UserName/Password

ROBOCOPY network UserName/Password

September 19, 2012 Leave a comment Go to comments

If you need to copy something using robocopy to remote host where additional authentication is required you should send username/password somehow. Robocopy.exe does not provide network authentication by itself. So to provide username and password for robocopy.exe we can use NET USE to open IPC$ share to destination host and execute our robocopy code.

  • Note: There is UNC path used, so keep in mind to have source and destination folders shared.

    • Script language: cmd / bat
    NET USE \\RemoteServerName\IPC$ /u:server\user *password* 
    robocopy \\Source\ \\RemoteServerName\DestinationDir\ /XD * /Z /MIR /LOG+:c:\temp\log.log
    NET USE \\RemoteServerName\IPC$ /D

    Code comments:

    /XD * – exclude ALL sub directories
    /Z – copy files in restartable mode (survive network glitch)
    /D – close IPC$ share to make our script clean


    • Script language: PowerShell
      • Has parameters to customize script
      • Can send log file by email.
    # IPC$ share options                #
    $IPCHost = "host_name" # Host name to create IPC$ share with
    $IPCUser = "domain\user" # Authentication
    $IPCPwd = "Pa$$w0rd" # for IPC$ share
    # Copy TO settings #
    $DstHost = "host_name" # Destination Host Name
    $DstDir = "root_share\folder\name" # Destination Directory Path
    # Copy FROM settings #

    $SrcHost =
    "host_name" # Source Host Name
    $SrcDir = "root_share\folder\name" # Source Directory Path
    # E-Mail Settings #
    $LogPath = "c:\full_path.log" # Full path to log file (c:\temp.name.log)
    $EmailTo = "email@domain.com" # Recipient email address
    $EmailFrom = "
    email@domain.com" # Sender email address
    $EmailSubj = "subject_here" # Letter Subject
    $EmailBody = "body_here" # And body
    $EmailSmtpSrv = "server_name" # SMTP server name (FQDN)
    # Parameters (robocopy keys) #
    $Params = "/XD * /Z /MIR" # Specify needed robocopy.exe parameters here
    # Action Block #
    NET USE \\$IPCHost\IPC$ /u:$IPCUser $IPCPwd
    robocopy.exe \\$SrcHost\$SrcDir\ \\$DstHost\$DstDir\ $Params /LOG:$LogPath
    NET USE \\$IPCHost\IPC$ /D
    Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $EmailSubj -Body $EmailBody -SmtpServer $EmailSmtpSrv -Attachments $LogPath

    Categories: Scripting
    1. Tom
      September 27, 2013 at 19:50

      thanks a TON!

    2. noname
      December 15, 2013 at 16:28

      it works like a charm ! Thx

    3. July 8, 2015 at 03:50

      Nice tip, thank you!

    4. Victor
      July 29, 2015 at 13:10

      HI

      I think there’s a hiccup: the NET USE bit looks like it’s missing a drive letter’ and this drive letter is meant to be referred to in the robocopy.exe bit:
      LIke NET USE Z: \\REMOTESERVER\REMOTEDIR /U:REMOTEUSER REMOTEUSERPASS
      ROBOCOPY.EXE LOCALDIR|UNC Z: $PARMS
      NET USE Z: -D

      Otherwise, you are mapping a letterless drive; and not referring to it in the copy if I am not mistaken.

      Thanks for a great article.
      Vic

    5. Victor
      July 29, 2015 at 13:19

      I made a comment earlier, elaborating on my ignorance. please discard it; your work rocks.

    6. September 3, 2015 at 13:24

      Great script. Thanks for sharing

    7. January 12, 2016 at 13:38

      To copy files from one system to another remote system follow these simple steps:
      1) login to the remote system using this command
      NET USE \\RemoteServerName\IPC$ /u:username password
      2)Go to the directory in which we have the file for example cd c:progfiles/
      3) Then use this commad
      ROBOCOPY “file name to be copied” “\\ip address of the remote machine\pathname\”file name to be copied” /MIR

    8. Kelly Grillo
      October 7, 2016 at 00:57

      Thanks man! What a great post… to the point and very clear!

    9. vikas khandola
      February 14, 2018 at 18:56

      use robocopy

    10. GGWP
      May 21, 2018 at 12:34

      I love you

    11. Rafael
      July 13, 2018 at 05:35

      Thank YOu so Much! congrats

    12. July 27, 2018 at 15:11

      Thanks the script it works like a charm, i am wondering if could limit the notification over the email if it failed to copy any content on any destination.

      Please help what parameters to use to get email for a failed output.

    13. sridhar
      September 26, 2019 at 19:29

      I am using different domain user, I am getting user name or password is incorrect.

    14. March 19, 2020 at 08:51

      Tremendous things here. I’m very satisfied to see your article.
      Thank you a lot and I am taking a look forward to touch you.
      Will you please drop me a e-mail?

    15. August 4, 2021 at 08:36

      Thanks, Is there any way to hide password, so if somebody open batch script can not see user and pass?

    16. August 4, 2021 at 09:14

      Good Solution for small Server rooms

    17. Carlos
      December 26, 2022 at 19:40

      Two words: “THANK YOU”

    1. August 23, 2021 at 18:18
    2. September 25, 2021 at 03:17
    3. December 12, 2021 at 22:17
    4. April 7, 2022 at 06:31
    5. April 17, 2022 at 13:36
    6. December 29, 2022 at 08:03

    Leave a comment