Powershell - Run a script located at a remote mach

2019-03-01 04:41发布

I'm trying to execute a powershell script located at a remote machine using the below command and it works great

invoke-command (powershell c:\install\install.ps1) -computername box1 -credential (get-credential)

The above script in-turn copies files from a network share (using robocopy) - It fails complaining the location doesn't exist. Found out it was due to permission issue. It works when I explicitly mentioned in the script to use the following credentials for the share

net use \share1\files password /user:username

Is there a way to pass in the same credentials used to run the script to be used by the script to access other resources in the remote machine?

Thanks! Sanjeev

2条回答
放荡不羁爱自由
2楼-- · 2019-03-01 05:19

Pass the credentials as arguments to the power shell script when invoking it remotely using invoke-command. Pass these credentials to the next script from install.ps1.

查看更多
爷的心禁止访问
3楼-- · 2019-03-01 05:24

What you need is credSSP. Check this post: http://www.ravichaganti.com/blog/?p=1230

查看更多
登录 后发表回答