Identify JSON properties dynamically based on value

Nandan Hegde 36,716 Reputation points MVP Volunteer Moderator
2022-12-26T12:06:13.407+00:00

I have a scenario wherein I am not sure what would be the JSON output values/structure as it changes based on different input values :

1st scenario :
274044-image.png

2nd scenario:
274063-image.png

I need the JSON property that has values like AzurekeyvaultsecretReference.

So w.r.t 1st scenario, we need
MWSAUthToken
Secretkeys as my output

and in case of 2nd scenario, output should be accountkey

@Rich Matheisen

Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 48,026 Reputation points
    2022-12-26T20:18:06.847+00:00

    The Invoke-RestMethod should, in this case, be returning a PSObject. If you know the property name you should be able to access its value directly. If the property doesn't exist you'll get a $null value. You should also find the names of all the PSObject properties in the object if you want to verify whether the property exists regardless of its value.

    What you've provided in your screenshots are the textual representations of the PSObject returned from two different instances of a PSObject.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.