0

I am running Invoke-RestMethod to get a response from an API. That response is in JSON format and I am trying to figure out how to get access to the individual properties in my Powershell code.

Given these two lines:

$response = Invoke-RestMethod -Uri $paymentJournalUri -Method 'GET' -Headers $headers | ConvertTo-Json
Write-Host $response

my output looks like this:

{
    "@odata.context":  "https://api....yments",
    "value":  [
                  {
                      "@odata.etag":  "W/\"JzI....Dsn\"",
                      "id":  "b86ac....8fab",
                      "journalId":  "59....b3ca",
                      "journalDisplayName":  "EFT",
                      "lineNumber":  30000,
                      "vendorId":  "a4c...552",
                      ...

So how can I loop over the 'value' array and get access to each of those properties?

I have tried something like this:

$PSObj = $response | ConvertTo-Json

#Write-Host $PSObj

$PSObj.value | ForEach-Object {
    Write-Host $_.journalDisplayName
}
dmikester1
  • 1,374
  • 11
  • 55
  • 113

0 Answers0