I'm using the new MS Graph PowerShell cmds, and trying to get a list of all the users assigned as owners of an Azure AD application registration using the cmd Get-MgApplicationOwner
Get-MgApplicationOwner -ApplicationId $appObjectId
This gives me the results as below, with 2 user owners
Id | DeletedDateTime | AdditionalProperties |
---|---|---|
00000000-0000-0000-0000-000000000000 | -- | {[@odata.type, #microsoft.graph.user], [businessPhones, System.Object[]], [displayName, User1 LastName], [givenName, User1]...} |
00000000-0000-0000-1111-000000000000 | -- | {[@odata.type, #microsoft.graph.user], [businessPhones, System.Object[]], [displayName, User2], [userPrincipalName, [email protected]]} |
If I do (Get-MgApplicationOwner -ApplicationId $appObjectId).AdditionalProperties
, I can see all the properties of the 2 users as 1 table
Key | Value |
---|---|
@odata,type | "#microsoft,graph,user" |
businessPhones | {1234567890} |
displayName | User1 LastName |
givenName | User1 |
[email protected] | |
surname | LastName |
userPrincipalName | [email protected] |
@odata,type | #microsoft,graph,user |
businessPhones | {} |
displayName | User2 |
userPrincipalName | [email protected] |
I'm trying to get the UserPrincipalNames
from this AdditionalProperties
array, and
I've tried dot-notation (Get-MgApplicationOwner -ApplicationId $appObjectId).AdditionalProperties.UserPrincipalName
but no luck. I know I could do a lookup against each Id but would prefer not to
Desired output as an array
[email protected]
[email protected]
CodePudding user response:
Actually I found the answer is that the key value was case-sensitive. Both dot-notation and SantiagoSquarzon's solution work when using case-correct userPrincipalName