I am trying to use PowerShell to extract value from JSON object, I have the following JSON:
{
"aad.NTA5YjRjYTItNDFjNi03OTQ1LTlmNTYtM2MyOGI1NWE5MTU5": {
"descriptor": "aad.NTA5YjRjYTItNDFjNi03OTQ1LTlmNTYtM2MyOGI1NWE5MTU5",
"directoryAlias": "dis3yv",
"displayName": "Tom Test",
"domain": "ea80952e-a476-42d4-aaf4-5457awesfre",
"legacyDescriptor": null,
"mailAddress": "[email protected]",
"metaType": "member",
"origin": "aad",
"originId": "919579e1-6e98-47fd-adb3-3d52d0467037",
"principalName": "[email protected]"
},
"aad.NmE5ODg4ODQtM2EyNS03ZjBiLWI0OTItN2JmMDA1MzVkNmJi": {
"descriptor": "aad.NmE5ODg4ODQtM2EyNS03ZjBiLWI0OTItN2JmMDA1MzVkNmJi",
"directoryAlias": "cup7mz",
"displayName": "Dummy May",
"domain": "ea80952e-a476-42d4-aaf4-5457852b0f7e",
"legacyDescriptor": null,
"mailAddress": "[email protected]",
"metaType": "member",
"origin": "aad",
"originId": "71e2fa85-59f0-4d8f-a5a9-4ff3e23d01d9",
"principalName": "[email protected]",
"subjectKind": "user"
}
}
Here I want to extract mailaddress from this file using powershell, and assign it to variable.
The problem I have is the top value "aad.*" keeps changing and I want to be able to automat this so I can have all the mailaddresses in an array or something
so i can't use
$yourVariable = (Get-Content 'yourJsonFilePath.json' | ConvertFrom-Json).aad.NTA5YjRjYTItNDFjNi03OTQ1LTlmNTYtM2MyOGI1NWE5MTU5.mailaddress
because the value keeps changing
Anyone know how to do this ?