1

I have json that I get from an API that returns a value like this

[{
    "Location": "/xxx/005D2"
}, {
    "Location": "/xxx/020D2"
}, {
    "Location": "/xxx/061D2"
}, {
    "Location": "/xxx/086D2"
}, {
    "Location": "/xxx/100D2"
}]

When I call the URL and access the variable

$installs= Invoke-RestMethod -Uri $installLocation -Method Get;

I get the following

Location
--------------
/xxx/100D2
/xxx/120D2
/xxx/110D2
etc

How can I loop through these so I only access 1 location at a time?

1
  • 1
    $installs | foreach { $_.location; }; Commented Aug 13, 2018 at 18:34

1 Answer 1

2

You acutally don't want to loop through JSON, but through a PowerShell object ($installs). You can do that, as with any other PowerShell object.

$installs | ForEach-Object {
    $_.Location
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.