title: Enabling execution policy for PowerShell from C#
body: <p>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 <em>Unrestricted</em> policy. How can I force the PowerShell child to use <em>Unrestricted</em> policy?</p>
  
  <p>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.</p>
  
  <pre><code>    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();
          }
      }
  </code></pre>