Powershell,拒绝对网络资源的远程脚本访问 [英] Powershell, remote script access denied to network resources
问题描述
我正在尝试使用 invoke-command 远程执行 powershell 脚本.该脚本依赖于本地网络上可用的配置文件.脚本的调用方式如下:
Invoke-Command -ComputerName 192.168.137.181 -FilePath c:\scripts\script.ps1 -ArgumentList \\192.168.137.1\share\config.xml
您所看到的配置是一个 xml 文件,它使用以下方式加载:
$xml = 新对象 XML$xml.Load(args[0])
当脚本在机器上本地调用时,它会毫无问题地运行并读取配置文件.但是,当我使用 invoke 命令从不同的机器运行它时,我得到 p><块引用>
访问路径 '\\192.168.137.1\share\config.xml' 被拒绝"
异常,执行Load方法时抛出.
具有读写权限的所有人都可以访问该文件.应该运行脚本的机器 (.181) 和实际运行它的机器都具有相同的凭据,因此我不会在 invoke-command cmdlet 中传递它们.共享机器 (.1) 具有不同的凭据,但从 .181 本地调用脚本时,这从来都不是问题.
你能指出我正确的方向吗?我坚持这一步,无法自己找到解决方案.我尝试使用 WebClient#DownloadString 方法下载 xml 字符串并传递共享机器的凭据,但没有帮助.
提前致谢
这可能是 double hop
问题.您必须使用 CredSSP 将您的凭据委托给远程计算机.
试试这里提到的解决方案:http://blogs.msdn.com/b/clustering/archive/2009/06/25/9803001.aspx
I am trying to execute powershell script remotely using invoke-command. The script relies on a configuration file which is available over the local network. The script is called in a following way:
Invoke-Command -ComputerName 192.168.137.181 -FilePath c:\scripts\script.ps1 -ArgumentList \\192.168.137.1\share\config.xml
The configuration as you can see is an xml file and it's loaded using:
$xml = New-Object XML
$xml.Load(args[0])
When the script is called locally on the machine then it runs witout any problems and reads the configuration file. However when I run it from different machine using invoke command I get
"Access to the path '\\192.168.137.1\share\config.xml' is denied"
exception, which is thrown when executing Load method.
The file is accessible to everyone with read and write permissions. Both, machine on which the scrip should be run (.181) and the machine on which it is run physically have the same credentials, thus I do not pass them in invoke-command cmdlet. The share machine (.1) has different credential, but this was never an issue when calling the script locally from .181.
Can you please point me in the right direction? I stuck on this step and can't find solution by myself. I tried downloading the xml string using WebClient#DownloadString method and passing credentials for the share machine but it did not help.
Thanks in advance
It is probably a double hop
issue. You have to use CredSSP to delegate your credentials to the remote computer.
Try the solution mentioned here: http://blogs.msdn.com/b/clustering/archive/2009/06/25/9803001.aspx
这篇关于Powershell,拒绝对网络资源的远程脚本访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!