--- title: "Create Dynamic Groups in Entra ID with Location and Group Membership Rules" slug: "dex-wf-dynamic-groups-location-and-membership" updated: 2026-11-30T16:15:30Z published: 2026-11-30T16:15:30Z canonical: "documentation.sysaid.com/dex-wf-dynamic-groups-location-and-membership" --- > ## Documentation Index > Fetch the complete documentation index at: https://documentation.sysaid.com/llms.txt > Use this file to discover all available pages before exploring further. # Create Dynamic Groups in Entra ID with Location and Group Membership Rules Combine location-based criteria and group membership using nested dynamic groups. **Complexity:** Intermediate. **Impact:** access-management + group-lifecycle + automation + entra-id. ## Why use this workflow Dynamic groups in Microsoft Entra ID populate their membership automatically based on user attributes (city, state, department) or membership in other groups. This workflow addresses a common requirement: **combining location-based criteria with group membership** in one logical grouping, for example everyone in a specific region *plus* everyone in a specific team. A limitation of Entra ID drives the design: **the `memberOf` attribute cannot be combined with other rules** (such as `user.city` or `user.state`) in a single dynamic membership rule. Attempting it returns a `DynamicGroupQueryParseError`. The workaround is a three-group architecture: two dynamic groups (one per rule type) rolled up under a static parent group through nested group membership. Run this workflow when you need distribution lists, access groups, or notification targets that combine geographic or organizational attributes with explicit team membership. ## Expected outcomes - A **location-based dynamic security group** that populates automatically from user attributes (city, state, country). - A **memberOf dynamic security group** that mirrors the membership of a source team or group. - A **static parent security group** with both dynamic groups nested as members, which gives you a single handle for the combined population. - A reusable architecture pattern for future requests that combine dynamic criteria with group membership. ## Risks and considerations ### Known limitations - **`memberOf` cannot be combined with other rules.** This is why the workflow uses three groups instead of one. - **Nested group resolution is inconsistent across Microsoft 365 services.** Group-based licensing, some Conditional Access scenarios, and certain Exchange features do *not* resolve nested group membership. Test your specific use case. - **Security groups are not mail-enabled.** If you need a distribution list for email, create a mail-enabled distribution group or a Microsoft 365 group separately. Security groups cannot be converted. - **Licensing.** Dynamic membership requires Microsoft Entra ID P1 or P2 licenses for the users in scope. ### Gotchas - Initial population of a dynamic group is not immediate. If membership is empty right after creation, wait and check again. - User attributes such as `city` and `state` are free text. Your rule must account for variations (for example, `"Vaud"` and `"VD"`). - Using `contains()` in a Graph `$filter` on groups is **not supported**. Use `startswith()` or `eq`. - The correct memberOf syntax is `user.memberOf -any (group.objectId -in ['guid'])`, not `group.id`. ## Required permissions | Permission | Why it's needed | | --- | --- | | Group.ReadWrite.All | Required to create security groups, set dynamic membership rules, and add members to the parent group. | | Directory.Read.All | Required to look up the source group and inspect user attributes when you design the membership rule. | ## Ask Dex Paste the prompt into a Dex conversation. ### Prompt for IT admins ``` Create a dynamic distribution group named {parent_group_name} in Entra ID that combines users from {location} (state or city match) with all members of the {source_group} team. Use the supported nested-group pattern: a dynamic location group, a dynamic memberOf group, and a static parent group containing both. ``` ## Manual steps (admin center) ### Step 1: Create the location-based dynamic group 1. Sign in to the [Microsoft Entra admin center](https://entra.microsoft.com) as at least a **Groups Administrator**. 2. Go to **Identity** > **Groups** > **All groups** > **New group**. 3. Configure the group: - **Group type:** Security - **Group name:** `{region}-location-members` (for example, `lausanne-vaud-members`) - **Membership type:** Dynamic User 4. Select **Add dynamic query** and enter a rule such as: ``` (user.state -eq "Vaud") or (user.state -eq "VD") or (user.city -eq "Lausanne") ``` 5. Select **Save**, then **Create**. ### Step 2: Create the memberOf dynamic group 1. Create another group with the name `{region}-{team}-members` (for example, `lausanne-clinbio-members`). 2. Set **Membership type** to **Dynamic User**. 3. In the dynamic query, use the rule syntax editor and enter: ``` user.memberOf -any (group.objectId -in ['']) ``` 4. Save and create the group. ### Step 3: Create the static parent group 1. Create a new group with the name `{region}-members` (for example, `lausanne-members`). 2. Set **Membership type** to **Assigned**. 3. After creation, open the group, go to **Members** > **Add members**. 4. Search for and add both dynamic groups created in steps 1 and 2. ### Step 4: Verify 1. Wait for the dynamic rules to process. 2. Open each dynamic group, go to **Members**, and confirm that users are populated. 3. Open the parent group and confirm that both dynamic groups appear as members. ## Microsoft Graph API All calls use `https://graph.microsoft.com/v1.0` as the base URL and require `Group.ReadWrite.All`. ### 1. Find the source group (to get its object ID) ``` GET /groups?$filter=startswith(displayName,'{TeamName}')&$select=id,displayName ``` Note the returned `id`. You use it as `<SOURCE-GROUP-GUID>` below. ### 2. Create the location-based dynamic group ``` POST /groups Content-Type: application/json {  "displayName": "{region}-location-members",  "description": "Users located in {region}.",  "mailEnabled": false,  "securityEnabled": true,  "groupTypes": ["DynamicMembership"],  "mailNickname": "{region}-location-members",  "membershipRule": "(user.state -eq \"Vaud\") or (user.state -eq \"VD\") or (user.city -eq \"Lausanne\")",  "membershipRuleProcessingState": "On" } ``` The `201 Created` response returns the new group's `id`. Save it as `<LOCATION-GROUP-ID>`. ### 3. Create the memberOf dynamic group ``` POST /groups {  "displayName": "{region}-{team}-members",  "mailEnabled": false,  "securityEnabled": true,  "groupTypes": ["DynamicMembership"],  "mailNickname": "{region}-{team}-members",  "membershipRule": "user.memberOf -any (group.objectId -in [''])",  "membershipRuleProcessingState": "On" } ``` Save the returned `id` as `<MEMBEROF-GROUP-ID>`. ### 4. Create the static parent group ``` POST /groups {  "displayName": "{region}-members",  "mailEnabled": false,  "securityEnabled": true,  "groupTypes": [],  "mailNickname": "{region}-members" } ``` Save the returned `id` as `<PARENT-GROUP-ID>`. ### 5. Nest the two dynamic groups under the parent ``` POST /groups//members/$ref { "@odata.id": "https://graph.microsoft.com/v1.0/groups/" } ``` ``` POST /groups//members/$ref { "@odata.id": "https://graph.microsoft.com/v1.0/groups/" } ``` Both calls return `204 No Content` on success. ### Common errors - `DynamicGroupQueryParseError: Unsupported property 'id'`: use `group.objectId`, not `group.id`, in memberOf rules. - `Filter operator 'Contains' is not supported`: use `startswith()` when you search for groups. ## PowerShell These steps use the Microsoft Graph PowerShell SDK. Install it once with `Install-Module Microsoft.Graph -Scope CurrentUser`. ### 1. Connect to Graph ``` Connect-MgGraph -Scopes "Group.ReadWrite.All","Directory.Read.All" ``` ### 2. Look up the source group ``` $sourceTeam = "{TeamName}" $sourceGroup = Get-MgGroup -Filter "startswith(displayName,'$sourceTeam')" | Select-Object -First 1 $sourceGroupId = $sourceGroup.Id ``` ### 3. Create the location-based dynamic group ``` $locationGroup = New-MgGroup -BodyParameter @{    displayName = "lausanne-vaud-members"    mailEnabled = $false    securityEnabled = $true    groupTypes = @("DynamicMembership")    mailNickname = "lausanne-vaud-members"    membershipRule = '(user.state -eq "Vaud") or (user.state -eq "VD") or (user.city -eq "Lausanne")'    membershipRuleProcessingState = "On" } ``` ### 4. Create the memberOf dynamic group ``` $memberOfRule = "user.memberOf -any (group.objectId -in ['$sourceGroupId'])" $memberOfGroup = New-MgGroup -BodyParameter @{    displayName = "lausanne-clinbio-members"    mailEnabled = $false    securityEnabled = $true    groupTypes = @("DynamicMembership")    mailNickname = "lausanne-clinbio-members"    membershipRule = $memberOfRule    membershipRuleProcessingState = "On" } ``` ### 5. Create the parent group and nest the dynamic groups ``` $parent = New-MgGroup -DisplayName "lausanne-members" `    -MailEnabled:$false -SecurityEnabled:$true `    -MailNickname "lausanne-members" New-MgGroupMember -GroupId $parent.Id -DirectoryObjectId $locationGroup.Id New-MgGroupMember -GroupId $parent.Id -DirectoryObjectId $memberOfGroup.Id ```