title: VS2013 VB - Trying to add a Powershell output to ListBox
body: <p>I am having some real trouble here. Working in Visual Studio 2013 Express, in Visual Basic. I have a form which has a ListBox. And a function which calls a PowerShell cmd-let 'Get-Process'. I am trying to get this output to display in said Listbox.</p>
  
  <p>The code I have so far is below:</p>
  
  <pre><code>Private Function RunScript(ByVal scriptText As String) As String
          ' create Powershell runspace 
          Dim MyRunSpace As Runspace = RunspaceFactory.CreateRunspace()
          MyRunSpace.Open()
          ' create a pipeline and feed it the script text 
          Dim MyPipeline As Pipeline = MyRunSpace.CreatePipeline()
  
          MyPipeline.Commands.AddScript(scriptText)
          MyPipeline.Commands.Add("Out-String")
  
          ' execute the script 
          Dim PSOut As Collection(Of PSObject) = MyPipeline.Invoke()
  
          ' close the runspace 
          MyRunSpace.Close()
  
          For Each Id In PSOut
              CheckList1.BeginUpdate()
              CheckList1.Items.Add(Id)
              CheckList1.EndUpdate()
          Next
  
      End Function
  </code></pre>
  
  <p>All this does is display the first line of the PowerShell output and nothing else. What am I missing? I thought maybe it needs to be told to loop through the collection, but I cant find anything like that in my searches thus far...</p>
  
  <p>Any help will be appreciated.</p>
  
  <p>Phill</p>