Skip to main content
< All Topics
Print

Dynamic Membership Rules

This is for defining the criteria for dynamically adding membership to groups.

Basic format:

(user | device).attribute operator "value"

Examples:

  • Add all users in the “Marketing” department:
(user.department -eq "Marketing")
  • Add all users with job title containing “Manager”:
(user.jobTitle -contains "Manager")
  • Combine conditions (AND / OR):
(user.department -eq "Sales") -and (user.accountEnabled -eq true)
  • Exclude certain users:
(user.department -eq "HR") -and (user.userPrincipalName -ne "ceo@contoso.com")

Common Operators

OperatorMeaning
-eqEquals
-neNot equals
-containsContains substring
-notContainsDoes not contain substring
-startsWithStarts with
-endsWithEnds with
-inValue is in a list
-notInValue is not in a list

Context within PowerShell

# Create the group
$group = New-AzureADMSGroup

-DisplayName “Marketing Users” `
-MailEnabled $false `
-SecurityEnabled $true `
-MailNickname “MarketingUsers” `
-GroupTypes “DynamicMembership”

# Define the rule
$rule = ‘(user.department -eq “Marketing”)’

# Set the membership rule
Set-AzureADMSGroup -Id $group.Id `
-MembershipRule $rule `
-MembershipRuleProcessingState “On”

Table of Contents