Get-MgGroupMember not returning additional properties
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.
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"]}
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.
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"] }
}
)
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
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
PS /Users/aleksandrkolesnikov> Get-MgGroupMember -GroupId $MainGroup.Id -All | select -First 1 | select * -ExpandProperty additionalProperties
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.