How to get the Dynamic group membership using Get-MgGroup?

EnterpriseArchitect 6,041 Reputation points
2023-07-19T07:07:42.1833333+00:00

How can I get the specific Dynamic Group membership using the latest Get-MgGroup cmdlet ?

The article does not mention how to do it using the latest cmdlet: https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.groups/get-mggroup?view=graph-powershell-1.0

PS C:\WINDOWS\system32> Get-MgGroup -Filter "GroupTypes -eq 'DynamicMembership'"
Get-MgGroup : Invalid filter clause: Syntax error at position 12 in 'GroupTypes -eq 'DynamicMembership''.
Status: 400 (BadRequest)
ErrorCode: BadRequest
Date: 2023-07-19T07:10:20
Headers:
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
Date                          : Wed, 19 Jul 2023 07:10:19 GMT
At line:1 char:1
+ Get-MgGroup -Filter "GroupTypes -eq 'DynamicMembership'"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({ ConsistencyLe...ndProperty =  }:<>f__AnonymousType84`9) [Get-MgGroup_List], Exception
    + FullyQualifiedErrorId : BadRequest,Microsoft.Graph.PowerShell.Cmdlets.GetMgGroup_List
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Harpreet Singh Matharoo 8,401 Reputation points Microsoft Employee Moderator
    2023-07-19T08:04:19.65+00:00

    Hello @EnterpriseArchitect

    Thank you for reaching out. I would request you to please use following filter clause and it should work:

    Get-MgGroup -Filter "groupTypes/any(c:c eq 'DynamicMembership')" -All:$true | Select-Object Displayname,MembershipRule
    

    Sample Output:

    User's image

    I hope this helps and fixes your issue. Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Kev Kelly 190 Reputation points
    2023-07-19T08:05:22.1+00:00

    From your sample PowerShell, it looks as though you're trying to use Get-MgGroup and filter/return just the dynamic groups. The following simple PowerShell will achieve this:

    Get-MgGroup -Filter "groupTypes/any(c:c eq 'DynamicMembership')" -All:$true
    
    3 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.