Powershell - Run a script located at a remote machine which inturn access files from a network share

社会主义新天地 提交于 2019-12-04 04:58:32

问题


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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/4596053/powershell-run-a-script-located-at-a-remote-machine-which-inturn-access-files

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