title: powershell Import module not working properly
body: <p>How to verify whether module (Import module ) command is imported module successfully in C# ? I have my own custom powershell, which is imported in Windows powershell.I have written C# code which will import the my custom powershell into windows powershell, When I try to execute custom powershell command from code it is not returning any result whereas when i execute same command from windows powershell (By importing module and writing a custom powershell command) it is working. I am using following code</p>
  
  <pre><code>InitialSessionState initial = InitialSessionState.CreateDefault();
  initial.ImportPSModule(new string[] { "ABCD" });
  Runspace runspace = RunspaceFactory.CreateRunspace(initial);
  initial.ThrowOnRunspaceOpenError = true;
  runspace.Open();
  RunspaceInvoke runSpaceInvoker = new  RunspaceInvoke(runspace); 
  runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
  PowerShell ps = PowerShell.Create();
  ps.Runspace = runspace;      
  string script = System.IO.File.ReadAllText(@"D:\Export-Pipeline-Script.txt");
  ps.AddScript(script);
  ps.Invoke();
  ps.Commands.Clear();
  ps.AddCommand("Test2");
  Collection&lt;PSObject&gt; results1 = ps.Invoke();
  foreach (PSObject outputItem in results1)
  {
      if (outputItem != null)
      {
          Console.WriteLine(outputItem.ToString());
      }
  }  
  </code></pre>
  
  <p>In AddCommand the Test2 is a function in which I have written the custom powershell command. In the above code results1 always written count as "0" whereas when I changed the custom powershell command to windows powershell command like Get-Process, it works.</p>