title: I can not run SkypeOnline PowerShell script in c# program
body: <p>I am trying to run this SkypeOnline script in program on C#.
  And have exception.
  Script works well in PowerShell command line.</p>
  
  <pre><code>using (var powerShellInstance = PowerShell.Create())
  {
      powerShellInstance.Commands
          .AddCommand("Import-Module")
          .AddArgument("SkypeOnlineConnector");
  
      var script = 
          "$Username =\"username\"\n" + 
          "$Password =\"password\"\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";
  
      powerShellInstance.AddScript(script);
      powerShellInstance.Invoke();
  }
  </code></pre>
  
  <p>This it result Exception:</p>
  
  <pre><code>Unhandled Exception: System.Management.Automation.CmdletInvocationException: Method not found: 'Microsoft.IdentityModel.
  Clients.ActiveDirectory.AuthenticationResult Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.Acqui
  reToken(System.String, System.String, System.Uri, Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior)'. ---&gt;
   System.MissingMethodException: Method not found: 'Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult
  Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireToken(System.String, System.String, System.
  Uri, Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior)'.
     at Microsoft.Rtc.Management.OnlineConnector.GetAccessToken.BeginProcessing()
     at System.Management.Automation.Cmdlet.DoBeginProcessing()
     at System.Management.Automation.CommandProcessorBase.DoBegin()
     --- End of inner exception stack trace ---
     at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
     at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
     at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
     at System.Management.Automation.PowerShell.CoreInvokeHelper(TInput,TOutput)(PSDataCollection'1 input, PSDataCollectio
  n'1 output, PSInvocationSettings settings)
     at System.Management.Automation.PowerShell.CoreInvoke(TInput,TOutput)(PSDataCollection'1 input, PSDataCollection'1 ou
  tput, PSInvocationSettings settings)
     at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
     at MSPControl.Providers.MicrosoftOnline.Tests.Console.Program.Main(String[] args) in Program.cs:line 22
  </code></pre>