msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

Get-MgGroupMember not returning additional properties

Open CrazyCodeUK opened this issue 3 years ago • 5 comments

When using the Get-MgGroupMember command. Additional properties specified are not returned. eg:

Get-MgGroupMember -GroupId <any sid> -Property UserPrincipalName

Comparatively the /groups/{id}/members endpoints supports $select and returns additional properties.

The command returns the same results (without additional properties) between 2.0.0 preview5 and 1.23.0, as well as between 1.0 and beta endpoints.

This has the impact, when using the Microsoft.Powershell module compared to the graph api direct, of requiring an additional Get-MgUser request per object that requires additional details, which increases run time and puts additional unneeded load on the Graph API service.

CrazyCodeUK avatar Mar 08 '23 14:03 CrazyCodeUK

Powershell by default limits the output of some commands and so is the case for Get-MgGroupMember as well. With no further input, it only returns ID and deletedDateTime. To expand the properties the command returns, you can use Select to either select all with a wildcard * or select specific ones by naming them out. For example, you can use something like this Get-MgGroupMember -GroupId <ID here> | select * -ExpandProperty additionalProperties | Select-Object {$_.AdditionalProperties["userPrincipalName"]}

MeesVees avatar Mar 10 '23 09:03 MeesVees

Powershell by default limits the output of some commands and so is the case for Get-MgGroupMember as well. With no further input, it only returns ID and deletedDateTime. To expand the properties the command returns, you can use Select to either select all with a wildcard * or select specific ones by naming them out. For example, you can use something like this Get-MgGroupMember -GroupId <ID here> | select * -ExpandProperty additionalProperties | Select-Object {$_.AdditionalProperties["userPrincipalName"]}

Just a reminder about dot notation:

(Get-MgGroupMember -GroupID $GroupID).AdditionalProperties.userPrincipalName is a bit easier/cleaner for anyone else. needing to do this. Also a quick reminder that these properties are case sensitive :). PS spoils us often and we don't have to worry about case, but it often matters in Graph.

dotnvo avatar Apr 03 '23 13:04 dotnvo

In case you'd like to get in one variable with appropriate attributes.

Get-MgGroupMember -GroupId {GroupID} -All | select * -ExpandProperty additionalProperties | Select-Object @(
                'id'    
                @{  Name       = 'userPrincipalName'
                    Expression = { $_.AdditionalProperties["userPrincipalName"] }
                }
            )

iFestral avatar Apr 30 '24 09:04 iFestral

This is not working. Get-MgGroupMember -GroupId $groupId -All| Select -ExpandProperty AdditionalProperties only returns two properties - @odata.type and businessPhones.

It only works with Delegated but not AppOnly

himani-chi avatar May 01 '24 17:05 himani-chi

This is not working. Get-MgGroupMember -GroupId $groupId -All| Select -ExpandProperty AdditionalProperties only returns two properties - @odata.type and businessPhones.

I can't imagine how you tested it, but you need to extract AdditionalProperties.

PS /Users/aleksandrkolesnikov> Get-MgGroupMember -GroupId $MainGroup.Id -All | select -First 1 | fl
ezgif-5-883812b358

PS /Users/aleksandrkolesnikov> Get-MgGroupMember -GroupId $MainGroup.Id -All | select -First 1 | select * -ExpandProperty additionalProperties

ezgif-5-f31d847db6

It only works with Delegated but not AppOnly Haven't tried via App, but the discussion is not about the app (I think should work). The script is working daily with managed identity.

iFestral avatar May 02 '24 07:05 iFestral