我有一个MVC4页面,它调用了一个powershell.但是我遇到了问题,因为我使用的模块没有签名,所以我必须启用Unrestricted策略.如何强制powershell child使用Unrestricted Policy.我在我的脚本中启用了它,但它被忽略了.此外,当我尝试在代码中设置策略时,会抛出异常.
using (Runspace myRunSpace = RunspaceFactory.CreateRunspace())
{
myRunSpace.Open();
using (PowerShell powerShell = PowerShell.Create())
{
powerShell.Runspace = myRunSpace;
powerShell.AddCommand("Set-ExecutionPolicy").AddArgument("Unrestricted");
powerShell.AddScript(script);
objectRetVal = powerShell.Invoke();
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢,Al