我正在尝试使用invoke-command远程执行powershell脚本.该脚本依赖于可通过本地网络获得的配置文件.脚本以下列方式调用:
Invoke-Command -ComputerName 192.168.137.181 -FilePath c:\scripts\script.ps1 -ArgumentList \\192.168.137.1\share\config.xml
Run Code Online (Sandbox Code Playgroud)
您可以看到的配置是一个xml文件,它使用以下命令加载:
$xml = New-Object XML
$xml.Load(args[0])
Run Code Online (Sandbox Code Playgroud)
当在机器上本地调用脚本时,它运行没有任何问题并读取配置文件.但是,当我使用invoke命令从不同的机器运行它时,我得到了
"访问路径'\\ 192.168.137.1\share\config.xml'被拒绝"
异常,在执行Load方法时抛出.
具有读写权限的每个人都可以访问该文件.应该运行脚本的机器(.181)和运行它的机器都具有相同的凭据,因此我不会在invoke-command cmdlet中传递它们.共享计算机(.1)具有不同的凭据,但从.181本地调用脚本时,这从来不是问题.
你能指点我正确的方向吗?我坚持这一步,自己无法找到解决方案.我尝试使用WebClient#DownloadString方法下载xml字符串并传递共享计算机的凭据,但它没有帮助.
提前致谢
我在运行 gulp 任务以转换我的配置文件时遇到问题。它报告以下错误:
error MSB4062: The "TransformXml" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsof t.Web.Publishing.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confi rm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Run Code Online (Sandbox Code Playgroud)
任务的作用:
_msbuild.proj包含要转换的配置文件的文件。文件看起来是这样的(显然 Source、Transform 和 Destination 都是用真实数据填充的):<Project …Run Code Online (Sandbox Code Playgroud)