Dynamic membership processing can take anywhere from a few minutes to 24 hours. Monitor the processing status and validate that the correct users are being added.
# Check membership rule processing status
$group = Get-MgGroup -GroupId $newGroup.Id -Property MembershipRule,MembershipRuleProcessingState
Write-Host "Rule: $($group.MembershipRule)"
Write-Host "Processing State: $($group.MembershipRuleProcessingState)"
# Get current member count
$memberCount = (Get-MgGroupMember -GroupId $newGroup.Id).Count
Write-Host "Current members: $memberCount"
# List all members with their attributes
Get-MgGroupMember -GroupId $newGroup.Id | ForEach-Object {
$user = Get-MgUser -UserId $_.Id -Property DisplayName,Department,City,JobTitle
[PSCustomObject]@{
Name = $user.DisplayName
Department = $user.Department
City = $user.City
JobTitle = $user.JobTitle
}
} | Format-Table
Test your membership rule syntax:
# Validate rule syntax (create a test group first)
$testRule = '(user.department -eq "IT") and (user.city -in ["Bengaluru", "Mumbai"])'
# Check which users would match your rule
Get-MgUser -Filter "department eq 'IT'" -Property DisplayName,Department,City |
Where-Object { $_.City -in @("Bengaluru", "Mumbai") } |
Select-Object DisplayName,Department,City
Verification: Compare the users returned by your manual filter with the actual group members. They should match once processing completes.
Warning: If membership processing appears stuck after 24 hours, check your rule syntax and ensure all referenced user attributes exist and are populated.