Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robocopy as another user

Problem: Robocopy not launching as another user in Start-Process

The script works fine when running on an account that has the permissions for both file locations but it just doesnt seem to be accepting the -credential param.

Unsure if my formatting is incorrect or if I am doing something wrong.

# Create Password for credential
$passw = convertto-securestring "Password" -asplaintext –force
# Assembles password into a credential
$creds = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\Username", $passw
# Select a source / destination path, can contain spaces
$Source = '\\Source\E$\Location'
$Destination = '\\Destination\Location Here'
# formats the arguments to allow the credentials to be wrapped into the command
$RoboArgs = "`"$($Source)`" `"$($Destination)`"" + " /e /Copy:DAT"
# Started Robocopy with arguments and credentials
Start-Process -credential $creds Robocopy.exe -ArgumentList $RoboArgs -Wait
like image 389
Drew Avatar asked Aug 22 '18 04:08

Drew


People also ask

How do I enter my credentials in robocopy?

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.

How do I transfer robocopy to another domain?

One way is to first mount the drives/folders from the source and destination servers (this will require the credentials), then run the robocopy command. For example: net use \\SourceServer\D$ /user:Domain1\Admin1 * net use \\DestinationServer\D$ /user:Domain2\Admin2 *

How do you use robocopy commands?

Copy examples The easiest way to copy a folder with all files and subfolders is to run this command: robocopy c:\temp\source c:\temp\destination /E /DCOPY:DAT /R:10 /W:3. The /E switch tells Robocopy to copy all subfolders, including empty ones. If you don't want to copy empty subfolders, use the /S switch.


1 Answers

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

like image 128
S.Spieker Avatar answered Sep 30 '22 22:09

S.Spieker