Robocopy as another user

狂风中的少年 提交于 2019-12-02 00:17:17

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.

net use X: '\\Source\E$\Location' /user:MYDOMAIN\USER THEPASSWORD
net use Y: '\\Destination\Location Here' /user:MYDOMAIN\USER THEPASSWORD

net use X: /d
net use Y: /d

and then start your ROBOCOPY

S.Spieker's answer will work, but if you want to use PowerShell built in command and pass the credentials as a pscredential object you could use New-PSDrive to mount the drives:

    $passw = convertto-securestring "Password" -asplaintext –force
    $creds = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\Username", $passw
    $SourceFolder = '\\Source\E$\Location'
    $DestinationFolder = '\\Destination\Location Here'

    New-PSDrive -Name MountedSource -PSProvider FileSystem -Root $SourceFolder -Credential $creds
    New-PSDrive -Name MountedDestination -PSProvider FileSystem -Root $DestinationFolder -Credentials $creds

    Robocopy.exe \\MountedSource \\MountedDestination /e /Copy:DAT"

    Remove-PSDrive -Name MountedSource 
    Remove-PSDrive -Name MountedDestination 

* I might have the Robocopy wrong, it's been years since I used it, but the mounting drives is correct.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!