Powershell - 运行位于远程计算机的脚本,该脚本反过来从网络共享访问文件

发布于 2024-10-10 18:33:50 字数 365 浏览 0 评论 0原文

我正在尝试使用以下命令执行位于远程计算机上的 powershell 脚本,它效果很好

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

上面的脚本-turn 从网络共享复制文件(使用 robocopy) - 它失败,抱怨位置不存在。发现是因为权限问题。当我在脚本中明确提到使用以下凭据进行共享

net use \share1\files 密码 /user:username

时,它​​会起作用 有没有办法传递用于运行脚本的相同凭据以供脚本使用访问远程计算机中的其他资源?

谢谢! 桑吉耶夫

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

递刀给你 2024-10-17 18:33:50

您需要的是 credSSP。检查这个帖子:
http://www.ravichaganti.com/blog/?p=1230

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

季末如歌 2024-10-17 18:33:50

使用 invoke-command 远程调用 Power shell 脚本时,将凭据作为参数传递给 Power shell 脚本。将这些凭据从 install.ps1 传递到 next 脚本。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文