title: The term 'New-CsOnlineSession' is not recognized as the name of a cmdlet
body: <p>I am trying to run a power shell script from the c#.
  When running the power shell script only, it runs successfully. But , while trying to run the same script from the c# . I get the error "The term 'New-CsOnlineSession' is not recognized as the name of a cmdlet"</p>
  
  <p>Here is the code:</p>
  
  <pre><code>          public static void GetLyncUsers(string userName, string password)
          {
              using (PowerShell powerShellInstance = PowerShell.Create())
              {
  
                  var script = string.Format("$Username =\"{0}\"\n" +
                                             "$Password =\"{1}\"\n" +
                                             "$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force\n" +
                                             "$cred = new-Object System.Management.Automation.PSCredential ($Username  , $secpasswd)\n" +
                                             "$CSSession = New-CsOnlineSession -Credential $cred\n" +
                                             "Import-PSSession $CSSession -AllowClobber\n" +
                                             "Get-CsOnlineUser", userName, password);
  
                  // use "AddScript" to add the contents of a script file to the end of the execution pipeline.
                  // use "AddCommand" to add individual commands/cmdlets to the end of the execution pipeline.
  
                  powerShellInstance.AddScript(script);
  
  
                  // use "AddParameter" to add a single parameter to the last command/script on the pipeline.
  
  
                  // invoke execution on the pipeline (collecting output)
                  Collection&lt;PSObject&gt; psOutput = powerShellInstance.Invoke();
  
                  // check the other output streams (for example, the error stream)
                  if (powerShellInstance.Streams.Error.Count &gt; 0)
                  {
                      // I am getting this error 
                    //The term 'New-CsOnlineSession' is not recognized as the name of a cmdlet
                  }
          }
  </code></pre>
  
  <p>Is there anything i am missing? I am new to powershell in general.</p>