【发布时间】:2021-09-11 07:50:06
【问题描述】:
我正在尝试从 C# 调用 PowerShell ISE 脚本。
我有在 PowerShell 上运行它的命令
. .\Commands.ps1; Set-Product -bProduct 'Reg' -IPPoint 'ServerAddress' -Location 'testlocation' -Terminal 3
现在我正在尝试使用 c# 创建命令,我已经编写了一些类似这样的代码。
//Set Execution Policy to un restrict
powershell.AddCommand("Set-ExecutionPolicy");
powershell.AddArgument("unrestricted");
powershell.Invoke();
powershell.Commands.Clear();
powershell.AddScript("K:\\Auto\\Cases\\Location\\Commands.ps1", false);
powershell.AddArgument("Set-Product").AddParameter("bProduct ", "Reg").
AddParameter("IPPoint", "ServerAddress").
AddParameter("Location", "testlocation").AddParameter("Terminal", 3);
powershell.Invoke();
我可以看到它运行良好。但它没有更新我的 xml 文件中的值。它假设更新我在文件中的值。当我尝试使用 powershell 运行它时,它确实运行并运行文件。但是c#代码不行。
任何提示或线索将不胜感激。
【问题讨论】:
标签: c# powershell command-line