Forum Discussion
Using PowerShell and Graph to get list of all owners of groups
VasilMichev - thank you for your response.
I added the Select in Graph Explorer and I like the result; however, when I applied it to my PowerShell script, I still don’t get the response I’m looking for the Display Name, UPN….
Snip-it from Graph Explorer
Updated Snip-it of PowerShell Script
$GOUri = "https://graph.microsoft.com/v1.0/groups/$GOObjectID/owners?`$select=ID,displayName,userPrincipalName"
$OwnerRequest = Invoke-RestMethod -Uri $GOUri -Headers $GOHeader -Method Get -ContentType "application/json"
$GOResults = $OwnerRequest.value
Foreach($GOResult in $GOResults)
{
Write-host $GOResult
Write-Host $GOResult.ID "..." $GOResult.displayName -ForegroundColor Yellow
}
The result from PowerShell sill only shows me the ID number and not the Display Name
Result of Write-host $GOResult : @{@odata.type=#microsoft.graph.user; id=37bca6da-aa3d-491a-b04f-6040a99b17e8; displayName=; userPrincipalName=}
Result Write-Host $GOResult.ID: "..." $GOResult.displayName -ForegroundColor Yellow: 37xxxxxx-xxxx-xxxx-xxxx-60xxxxxxxxxx …
Thank You,
-Larry
Works for me with or without adding the select statement. Check your permissions as well, they recently introduced some changes that might "hide" attribute values if you don't have sufficient permissions.
- EntilZhaApr 10, 2020Iron Contributor
Thank You, it was a permission issue. I had to add Directory.Read.All to the API Permissions.
Again Thank You Very Much!!!
-Larry
- VasilMichevApr 11, 2020MVP
Well I tried to explain to MS folks that this behavior will confuse people... Oh well.
- EntilZhaApr 10, 2020Iron Contributor
You were correct, I was missing a permission. Once I added Directory.Read.All to the API Permission it started working.
Again Thank You Very Much!!!!!
-Larry