What is a Dynamic Group in Azure (Microsoft Entra ID)?
A Dynamic Group in Microsoft Entra ID (formerly Azure Active Directory) is a security group or Microsoft 365 group whose membership is automatically managed based on user or device attributes.
- Instead of manually adding or removing members, administrators define dynamic membership rules.
- When a user or device attribute changes (such as
Department,JobTitle,City, orDeviceOSType), Entra ID automatically evaluates the rule and adds or removes the object. - Dynamic groups work for both Users and Devices (they cannot contain both in the same group).
Why Do Dynamic Groups Exist?
Managing static group memberships manually in growing cloud environments introduces significant operational and security challenges:
- Administrators must manually add new hires to dozens of groups for licensing, SharePoint sites, and Conditional Access policies.
- When employees change departments or locations, old group permissions are often left behind (privilege creep).
- Offboarded or deactivated accounts may retain access to sensitive resources if not promptly removed.
- Device-based policies (such as Intune compliance or app deployments) become difficult to scale across hundreds of Windows, iOS, or Android endpoints.
Dynamic Groups were introduced to:
- Automate onboarding, role changes, and offboarding access based on HR/directory attributes.
- Eliminate human error in group assignments.
- Keep Intune device targeting and Conditional Access policies continuously up to date.
- Enforce consistent role-based access control (RBAC) across Microsoft 365 and Azure.
Advantages of Using Dynamic Groups
Zero-Touch Onboarding and Role Changes
- New users automatically receive Microsoft 365 licenses, Teams memberships, and app access the moment their user attributes are populated.
- Changing a user’s
Departmentfrom Sales to Finance automatically swaps their group memberships without helpdesk tickets.
Improved Security and Compliance
- Reduces stale permissions and orphaned access when employees transfer roles.
- Ensures Conditional Access policies (such as requiring MFA for specific departments or device types) always target the right population.
Scalable Device Management
- Automatically groups corporate Windows 11 laptops, Autopilot devices, or specific OS versions for Microsoft Intune configuration profiles and app deployments.
Centralized Rule Logic
- All membership criteria live in one readable expression rather than scattered across manual scripts or spreadsheets.
Disadvantages and Limitations
Licensing Requirements
- Requires Microsoft Entra ID P1 or P2 licenses (or Microsoft 365 Business Premium / E3 / E5) for every user who is a member of a dynamic group.
Processing Delay
- Membership updates are not instantaneous; Entra ID typically evaluates changes within a few minutes, though large directories can take up to 24 hours.
Single Object Type per Group
- A dynamic group can target either Users or Devices—you cannot mix user accounts and device objects in the same dynamic rule.
Nested Groups Not Supported
- You cannot add another group as a member of a dynamic group; rules only evaluate direct user or device properties.
Prerequisites
Before creating a Dynamic Group in Microsoft Entra ID, ensure:
- Your tenant has Microsoft Entra ID P1 or P2 licensing enabled.
- You are signed in with a role that has group management permissions (Groups Administrator, User Administrator, or Global Administrator).
- Target user or device attributes (such as
Department,Country,UsageLocation, orextensionAttributes) are clean and consistently populated.
How to Create a Dynamic Group in Azure
Step 1: Open the Microsoft Entra Admin Center
- Sign in to the Microsoft Entra admin center (
https://entra.microsoft.com). - Navigate to Identity → Groups → All groups.
- Click New group.
Step 2: Configure Basic Group Settings
- Group type: Select Security (or Microsoft 365 if you want a collaborative team/mailbox).
- Group name: Enter a clear, standardized name (for example,
SG-Dyn-Dept-IT). - Group description: Briefly describe the rule purpose (for example,
Dynamic security group for all active IT department users). - Membership type: Change from Assigned to Dynamic User (or Dynamic Device).
Step 3: Add the Dynamic Membership Query
- Click Add dynamic query.
- Use the visual Rule builder dropdowns to select a Property, Operator, and Value, or click Edit next to Rule syntax to paste an expression directly.
- Click Save on the query builder, then click Create to provision the group.
Step 4: Create a Dynamic Group via PowerShell (Optional)
Run the following commands using the Microsoft Graph PowerShell SDK:
Connect-MgGraph -Scopes "Group.ReadWrite.All"
New-MgGroup -DisplayName "SG-Dyn-Dept-IT" `
-Description "Dynamic security group for IT department users" `
-MailEnabled:$false `
-MailNickname "SGDynDeptIT" `
-SecurityEnabled:$true `
-GroupTypes @("DynamicMembership") `
-MembershipRule '(user.department -eq "IT") and (user.accountEnabled -eq true)' `
-MembershipRuleProcessingState "On"
How to Create Dynamic Membership Expressions
Dynamic rules follow a standard syntax structure:
(Object.Property -Operator "Value")
Common Rule Operators
-eq: Equals-ne: Does not equal-startsWith: Starts with a specific string-contains: Contains a substring or value in a collection-match: Matches a regular expression (regex)-in: Matches any value in a listand/or: Combines multiple conditions
Example 1: All Active Users in a Specific Department
Includes only enabled user accounts where the Department attribute is set to IT:
(user.department -eq "IT") and (user.accountEnabled -eq true)
Example 2: Users Across Multiple Locations
Targets active employees located in either Melbourne or Sydney:
(user.city -in ["Melbourne", "Sydney"]) and (user.accountEnabled -eq true)
Example 3: Exclude Guest Accounts
Targets all internal member accounts while excluding external B2B guests:
(user.userType -eq "Member") and (user.accountEnabled -eq true)
Example 4: Corporate Windows Devices (Dynamic Device Rule)
Targets all company-owned Windows devices managed by Intune:
(device.deviceOSType -eq "Windows") and (device.deviceOwnership -eq "Company")
Example 5: Windows Autopilot Devices by Group Tag
Targets all Autopilot-registered devices assigned the Corporate group tag:
(device.devicePhysicalIDs -any (_ -eq "[OrderID]:Corporate"))
How to Validate Your Dynamic Rule
Before saving a complex expression in production, test it using Entra ID’s built-in Validate Rules preview tool:
- Open your dynamic group in Identity → Groups → All groups.
- Select Dynamic membership rules under the Manage section.
- Click the Validate Rules (Preview) tab at the top.
- Click Add users (or Add devices) and pick 3 to 5 test accounts—including accounts that should match and accounts that should not match.
- Click Validate to see a green checkmark or red cross explaining exactly why each object passed or failed the expression.
Best Practices
- Always filter by
accountEnabled -eq true: Prevent disabled or offboarded user accounts from continuing to consume licenses or trigger group evaluations. - Use a consistent naming convention: Prefix dynamic groups clearly (such as
SG-Dyn-for security groups andM365-Dyn-for Microsoft 365 groups) so administrators know not to edit membership manually. - Keep expressions simple: Avoid overly complex regex (
-match) rules where-startsWithor-inworks, as simpler rules evaluate faster across large tenants. - Standardize HR/AD attributes first: Dynamic groups are only as accurate as your directory data—enforce standardized spelling for
Department,Country, andJobTitle. - Test with Validate Rules before saving: Always verify rule changes against sample users before modifying expressions tied to Conditional Access or licensing.
Conclusion
Dynamic Groups in Azure (Microsoft Entra ID) eliminate repetitive manual group administration while strengthening security across your cloud environment. By combining clean directory attributes with well-structured membership expressions, you can automate licensing, application access, and device management from day one.
Good post. Thank you for sharing!