0

From my C# code, I'm calling a PowerShell file. This PowerShell file calls an API like this:

$tickets = Invoke-RestMethod -uri 'x'

return $tickets.value

From my C# code, I'm storing the returned result in a variable like this:

var tickets = pipeline.Invoke();

foreach (var ticket in tickets)
{
    System.Diagnostics.Debug.WriteLine(ticket.Status); //ERROR
}

I'm getting an error here saying that foreach cannot operate on variables of type System.Management.Automation.PSObject.

Printing 'tickets' returns this:

@{Id=581; CID=3; Status=Active}

@{Id=545; CID=6; Status=Active}

I need to be able to iterate through each ticket in tickets.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
90abyss
  • 7,037
  • 19
  • 63
  • 94

1 Answers1

0

This is how you do it:

System.Diagnostics.Debug.WriteLine(ticket.Properties["Status"].Value);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
90abyss
  • 7,037
  • 19
  • 63
  • 94