title: Pipeline.AsyncInvoke on a Powershell remote Pipeline
body: <p>I'm running remote powershell on Lync / S4f / Exchange servers. Synchronous operations all work fine, but I've hit a roadblock converting things to async.</p>
  
  <p>I managed to make the connection/disconnection async since the RunSpace offers your standard BeginOpen/EndOpen and BeginClose/EndClose operations, but InvokeAsync is of type void.</p>
  
  <p>Here's my code (connectionInfo is WSManConnectionInfo which has the uri set as follows</p>
  
  <pre><code>new Uri("https://" + config.Server + "/ocspowershell")
  </code></pre>
  
  <p>And this is the actual remote execution code</p>
  
  <pre><code>Runspace myRunSpace = RunspaceFactory.CreateRunspace(connectionInfo);
  myRunSpace.Open();
  using (Pipeline pipeLine = myRunSpace.CreatePipeline())
  {
      Command myCommand = new Command("Get-CsArchivingPolicy");
      pipeLine.Commands.Add(myCommand);
      pipeLine.StateChanged += PipeLine_StateChanged;
      waiter = new TaskCompletionSource&lt;Collection&lt;PSObject&gt;&gt;();
      pipeLine.Error.DataReady += Error_DataReady;
      pipeLine.Output.DataReady += Output_DataReady;
      pipeLine.InvokeAsync();
      pipeLine.Input.Close();
      await waiter.Task.ConfigureAwait(false);
  }
  </code></pre>
  
  <p>Here's what I'm seeing.. 
  If I don't close the input, nothing ever happens, other than the pipeline entering running state.</p>
  
  <p>As soon as I close the input, I do get Error_DataReady with 0 items to be read and EndOfPipeline being true, then I get a Output_DataReady, with EndOfPipeline being true but Count also being 0 (so calling Read on the reader doesn't work).</p>
  
  <p>Then the pipeline enters Completed state. So.. the command runs.. but where's the output?</p>
  
  <p>If I do pipeline.Invoke, I get a nice Collection back with my results.. so I know the command is correct. But I must be missing something regarding the output when running in async mode.</p>