title: Import-Module won't work when launched from .net
body: <p>I'm trying to run a powershell script within my C# web application.</p>
  <p>When i run the following in powershell, it works fine.</p>
  <pre><code>Import-Module 'C:\\Program Files\\Microsoft Dynamics NAV\\80\\Service\\NavAdminTool.ps1'
  
  Get-NAVTenant -ServerInstance DynamicsHost
  </code></pre>
  <p>But when i'm running it using my web application, it tells me</p>
  <blockquote>
  <p>The term 'Get-NAVTenant -ServerInstance DynamicsHost' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.</p>
  </blockquote>
  <p>Here is my c# code:</p>
  <pre><code>InitialSessionState initial = InitialSessionState.CreateDefault();
      initial.ImportPSModule(new string[] { &quot;C:\\Program Files\\Microsoft Dynamics NAV\\80\\Service\\NavAdminTool.ps1&quot; });
      Runspace runspace = RunspaceFactory.CreateRunspace(initial);
      runspace.Open();
      PowerShell ps = PowerShell.Create();
      ps.Runspace = runspace;
      ps.Commands.AddCommand(&quot;Get-NAVTenant -ServerInstance DynamicsHost&quot;);
  
      foreach (PSObject result in ps.Invoke())
      {
          Console.WriteLine(result.ToString());
      }
  </code></pre>
  <p>Can someone point me in the right direction??</p>
  <p>UPDATE:</p>
  <p>Using runspace.SessionStateProxy.PSVariable.GetValue(&quot;Error&quot;) i could see the following error:</p>
  <blockquote>
  <p>Cannot bind argument to parameter 'Name' because it is null.</p>
  <p>Cannot bind argument to parameter 'Path' because it is null.</p>
  <p>Cannot find path 'HKLM:\SOFTWARE\Microsoft\Microsoft Dynamics NAV\80\Service' because it does not exist.</p>
  <p>A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.</p>
  <p>A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.</p>
  <p>A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.</p>
  </blockquote>