I have an ASP.NET MVC 4 page that calls a piece of PowerShell. However, I am running into a problem as a module I am using is not signed, so I have to enable the Unrestricted policy. How can I force the PowerShell child to use Unrestricted policy?
I have enabled this in my script, but it is ignored. Also when I try to set the policy in code, an exception is thrown.
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();
}
}
Runspacewith some equivalent ofPowerShell.exe's-ExecutionPolicyparameter.