Using RoboCopy inside of Invoke-Command -Powershell Multihop Problems

While writing a script to invoke a robocopy on a remote server today, I ran into a problem. The files would not copy and Robocopy kept throwing the following error in the logs:

2014/06/11 10:56:09 ERROR 5 (0x00000005) Accessing Source Directory server01Repositorycontent
Access is denied.


This didn’t make a whole lot of sense to me, after all my script was passing credentials that had permissions to the fileshare… Here’s the script I was using:

invoke-command -credential (get-credential) -computername "" -scriptblock {c:windowssystem32robocopy.exe dco-util1Repositorycontent E:Test * /MIR /MT /LOG:E:LogFilesContentSyncSync13SharedTo2ContentLog.txt /R:10}

After checking the security logs in event viewer on the machine that was refusing the connection, I saw that the request was coming in as the computer name, rather than the credentials specified with the script. This was due to Powershell not being able to “multihop” or pass credentials out of the box. To resolve this, you can take the following actions.

Verify Powershell Remoting is enabled:


From the machine you are running the script on run the powershell command:

Enable-WSManCredSSP -Role Client -DelegateComputer "*"

On the machine on which the command is being invoked, run the powershell command:

Enable-WSManCredSSP -Role Server

Finally, change your script, to use credssp for authentication:

invoke-command -credential (get-credential) -authentication credssp -computername "", "" -scriptblock {c:windowssystem32robocopy.exe dco-util1Repositorycontent E:test * /MIR /MT /LOG:E:LogFilesContentSyncsync13sharedto2contentlog.txt /R:10}

More questions about Powershell remoting? Here’s a free Ebook that explains it better than I could:

I was originally helped quite a bit by this post:

Happy Remoting!


Leave a Reply

Your email address will not be published. Required fields are marked *