title: How to run Import-PSSessions from .Net program
body: <p>I am trying to write code in C# that get mailbox details from user via Power Shell command.</p>
  
  <p>The power shell command script is:  </p>
  
  <pre><code>Import-PSSession -session (New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://myServer.myDomain.com/Powershell)
  Get-Mailbox -Identity helpdesk
  </code></pre>
  
  <p>The script runs OK from PowerShell.</p>
  
  <p>Now my goal is to run it using C#.</p>
  
  <p>This is my function:</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)  
  {
      m_RunSpace = RunspaceFactory.CreateRunspace();
  
      m_RunSpace.Open();
  
      Pipeline pipeLine = m_RunSpace.CreatePipeline();
  
      Command newSession = new Command("New-PSSession");
      newSession.Parameters.Add("-ConfigurationName", "Microsoft.Exchange");
      newSession.Parameters.Add("-ConnectionUri", "http://myServer.myDomain.com/Powershell");
  
      Command createSessionForExch = new Command("Import-PSSession");
      createSessionForExch.Parameters.Add("-Session", newSession);
  
      Command getMailbox = new Command("Get-Mailbox");
      getMailbox.Parameters.Add("-Identity", "helpdesk");
  
      pipeLine.Commands.Add(createSessionForExch);
      pipeLine.Commands.Add(getMailbox);
  
      Collection&lt;PSObject&gt; commandResults = pipeLine.Invoke();
  
      foreach (PSObject cmdlet in commandResults)
      {
  
  
      }
  }
  </code></pre>
  
  <p>But I receive an error that the "Get-Mailbox" command is not recognize:
  <img src="https://i.stack.imgur.com/DnnJz.png" alt="enter image description here"></p>
  
  <p>Probably because the Import-PSSessions wasn't invok correctly.</p>
  
  <p>I need help how to run the command Import-PSSession correctly from C#</p>