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
memberOfcannot 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
cityandstateare free text. Your rule must account for variations (for example,"Vaud"and"VD"). - Using
contains()in a Graph$filteron groups is not supported. Usestartswith()oreq. - The correct memberOf syntax is
user.memberOf -any (group.objectId -in ['guid']), notgroup.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
- Sign in to the Microsoft Entra admin center as at least a Groups Administrator.
- Go to Identity > Groups > All groups > New group.
- Configure the group:
- Group type: Security
- Group name:
{region}-location-members(for example,lausanne-vaud-members) - Membership type: Dynamic User
- Select Add dynamic query and enter a rule such as:
(user.state -eq "Vaud") or (user.state -eq "VD") or (user.city -eq "Lausanne") - Select Save, then Create.
Step 2: Create the memberOf dynamic group
- Create another group with the name
{region}-{team}-members(for example,lausanne-clinbio-members). - Set Membership type to Dynamic User.
- In the dynamic query, use the rule syntax editor and enter:
user.memberOf -any (group.objectId -in ['<SOURCE-GROUP-GUID>']) - Save and create the group.
Step 3: Create the static parent group
- Create a new group with the name
{region}-members(for example,lausanne-members). - Set Membership type to Assigned.
- After creation, open the group, go to Members > Add members.
- Search for and add both dynamic groups created in steps 1 and 2.
Step 4: Verify
- Wait for the dynamic rules to process.
- Open each dynamic group, go to Members, and confirm that users are populated.
- 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,displayNameNote 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 ['<SOURCE-GROUP-GUID>'])",
"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/<PARENT-GROUP-ID>/members/$ref
{ "@odata.id": "https://graph.microsoft.com/v1.0/groups/<LOCATION-GROUP-ID>" }POST /groups/<PARENT-GROUP-ID>/members/$ref
{ "@odata.id": "https://graph.microsoft.com/v1.0/groups/<MEMBEROF-GROUP-ID>" }Both calls return 204 No Content on success.
Common errors
DynamicGroupQueryParseError: Unsupported property 'id': usegroup.objectId, notgroup.id, in memberOf rules.Filter operator 'Contains' is not supported: usestartswith()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.Id3. 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