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
What you need is credSSP. Check this post: http://www.ravichaganti.com/blog/?p=1230
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