title: Execute Powershell script in C# Unit Test
body: <p>Im trying to execute a powershell script to setup a vmware ENV before my Unit Test starts, in C#.</p>
  
  <p>When im trying to execute the powershell script in a Program.cs , it works fine.</p>
  
  <p>When i try to run it from a unit test the script dosent run and i can see an exception after the test starts.</p>
  
  <p><code>System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. This can happen if the test(s) started a thread but did not stop it. Make sure that all the threads started by the test(s) are stopped before completion.</code></p>
  
  <p>Here is a sample code for a test im running: </p>
  
  <pre><code>using T;
  
  namespace TTest
  {
      [TestClass]
      public class Convert
      {
          [TestMethod]
          public void convert()
          {
              Utility.prepC();
              string actual = Program.httpPost("http://10.1.1.1:1/aaa/bbb/ccc", "{\"id\":\"111\"}");            
              string expected = "true";
  
              Assert.AreEqual(expected, actual,"true", "pass");          
          }
  </code></pre>
  
  <p>Here is the Utility class : </p>
  
  <pre><code>namespace T
  {
      public class Utility
      { 
          static public void prepC()
          {
              PowerShell ps = PowerShell.Create();
              ps.AddScript("C:\\Users\\aaa\\Desktop\\C.ps1").Invoke();
          }
      }
  }
  </code></pre>