Empty powershell collection being returned from Pipeline.Invoke() in C#

Welcome Forums General PowerShell Q&A Empty powershell collection being returned from Pipeline.Invoke() in C#

Viewing 1 reply thread
  • Author
    Posts
    • #276135
      Participant
      Topics: 1
      Replies: 1
      Points: 11
      Rank: Member

      On Windows 10, in C# I am trying to call a powershell script via Pipeline.Invoke() to retrieve all the disks on a network server, for each server on a network. But can’t get it to return the data to C# when there are multiple disks on a server.

      I have the following C# code:

       

      which executes the following powershell script (GetDisks.ps1), with ComputerName hardcoded to a specific server for now:

      but it doesnt return a PSObjects collection into collDisks.

       

      It works in the ISE (and every re-arrangement I try seems to work there).

      It works if I run it for my local machine by removing -ComputerName SERVER01

      It doesnt make any difference if I try using PSCustomObject instead, or creating the object collection different ways.

       

      • This topic was modified 1 month, 2 weeks ago by kvprasoon. Reason: code formatting
      • This topic was modified 1 month, 2 weeks ago by kvprasoon. Reason: code formatting to handle single quotes
    • #276225
      Senior Moderator
      Topics: 9
      Replies: 1449
      Points: 5,428
      Helping Hand
      Rank: Community MVP

      Is there any error that you can capture from pipeline2 ?

      • #276534
        Participant
        Topics: 1
        Replies: 1
        Points: 11
        Rank: Member

        No. I checked through and couldn’t see any errors.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.