- Core Architecture: Replace manual user provisioning and static group tickets with attribute-driven Joiner-Mover-Leaver (JML) workflows powered by Microsoft Entra ID Dynamic Groups and Administrative Units (AUs).
- Delegation Boundary: Never grant tenant-wide
User AdministratororHelpdesk Administratorroles to regional IT teams—scope them to Restricted Management Administrative Units (RMAUs). - Automation Engine: All examples use PowerShell 7 and the Microsoft Graph SDK (
Microsoft.Graph.Users,Microsoft.Graph.Groups,Microsoft.Graph.Identity.DirectoryManagement) — completely eliminating legacyAzureADandMSOnlinemodules.
In Chapter 1: Tenant Architecture, Custom Domains, DNS & Group-Based Licensing, we established our foundational Microsoft 365 tenant, verified custom domains, and mapped group-based licensing. Now we tackle the operational heartbeat of every Microsoft 365 tenant: Identity Lifecycle Management.
When identity governance is handled manually through helpdesk tickets, three failure modes inevitably emerge:
- License Sprawl: Departed or transferred employees retain expensive E5 or Copilot licenses for months.
- Permission Creep: Users moving from Finance to Marketing keep access to Finance SharePoint sites and security groups.
- Over-Privileged Helpdesks: Regional support engineers are handed tenant-wide
User Administratorrights, enabling them to reset executive or break-glass passwords.
This chapter shows you how to architect a clean, self-maintaining Entra ID lifecycle using attribute hygiene, Dynamic Security Groups, Restricted Management Administrative Units (RMAUs), and automated offboarding scripts in Microsoft Graph PowerShell.
1. The Joiner-Mover-Leaver (JML) Architecture in Entra ID
Every identity in Microsoft Entra ID should flow through a deterministic, attribute-driven pipeline rather than ad-hoc manual clicks in the portal.
2. Standardizing User Attributes Before Writing Dynamic Rules
Dynamic groups are only as reliable as the directory attributes feeding them. Before creating rules, standardize these six core Entra ID user properties:
| Entra ID Property | Purpose | Example Value |
|---|---|---|
UsageLocation | Mandatory ISO 3166-1 alpha-2 code for license assignment | US, GB, IN, SG |
Department | Drives department security groups & SharePoint access | Finance, Engineering |
EmployeeType | Separates full-time employees from contractors/vendors | FTE, Contractor, Service |
Country | Drives regional Administrative Units & Conditional Access | United States, India |
AccountEnabled | Prevents disabled/leaver accounts from keeping licenses | true / false |
Manager | Required for Entitlement Management & Access Review approvals | Manager Object ID |
Audit Attribute Hygiene Across Your Tenant (PowerShell 7 + Graph SDK)
Connect-MgGraph -Scopes "User.Read.All"
$users = Get-MgUser -All -Property Id, DisplayName, UserPrincipalName, AccountEnabled, UsageLocation, Department, EmployeeType, Country, UserType |
Where-Object { $_.UserType -eq 'Member' -and $_.AccountEnabled -eq $true }
$hygieneReport = $users | ForEach-Object {
[PSCustomObject]@{
UPN = $_.UserPrincipalName
MissingUsageLoc = [string]::IsNullOrWhiteSpace($_.UsageLocation)
MissingDepartment = [string]::IsNullOrWhiteSpace($_.Department)
MissingEmployeeType = [string]::IsNullOrWhiteSpace($_.EmployeeType)
MissingCountry = [string]::IsNullOrWhiteSpace($_.Country)
}
} | Where-Object {
$_.MissingUsageLoc -or $_.MissingDepartment -or $_.MissingEmployeeType -or $_.MissingCountry
}
Write-Host "Active member accounts with incomplete lifecycle attributes: $($hygieneReport.Count)" -ForegroundColor Yellow
$hygieneReport | Export-Csv -Path ".\Entra-Attribute-Hygiene-Audit.csv" -NoTypeInformation
3. Building Production Dynamic Security Groups (Avoiding Deprecated Rules)
Important 2026 Compliance Note: Avoid using the deprecatedmemberOfdynamic membership rule preview syntax (see our dedicated Entra Dynamic GroupsmemberOfDeprecation Audit). Stick strictly to direct user attributes (department,employeeType,accountEnabled,country,extensionAttribute1-15).
Always include (user.accountEnabled -eq true) and (user.userType -eq "Member") in license-bearing dynamic groups so disabled leavers and B2B guests automatically drop out and free up licenses.
Create a Production Dynamic Licensing & Access Group via Graph PowerShell
Connect-MgGraph -Scopes "Group.ReadWrite.All"
$groupParams = @{
DisplayName = "SEC-LIC-M365-E5-Engineering-FTE"
Description = "Dynamic group assigning M365 E5 to active Engineering FTEs."
MailEnabled = $false
MailNickname = "sec-lic-m365-e5-eng-fte"
SecurityEnabled = $true
GroupTypes = @("DynamicMembership")
MembershipRule = '(user.accountEnabled -eq true) and (user.userType -eq "Member") and (user.department -eq "Engineering") and (user.employeeType -eq "FTE")'
MembershipRuleProcessingState = "On"
}
$newGroup = New-MgGroup -BodyParameter $groupParams
Write-Host "Created Dynamic Group: $($newGroup.DisplayName) (ID: $($newGroup.Id))" -ForegroundColor Green
Validate Dynamic Rule Syntax Before Enforcing
Use the Microsoft Graph evaluateDynamicMembership endpoint (or Entra Portal Validate Rules tab) to test rule syntax against real user Object IDs before turning MembershipRuleProcessingState to On.
4. Delegating Least-Privilege IT Support with Administrative Units (AUs)
In a multi-region or multi-subsidiary tenant, granting regional helpdesk teams tenant-wide Helpdesk Administrator or User Administrator roles is a major security risk—a compromised regional helpdesk account could target C-suite executives or sensitive accounts in another region.
Administrative Units (AUs) act like cloud Organizational Units (OUs) in Entra ID, allowing you to scope roles (User Administrator, Helpdesk Administrator, Groups Administrator, License Administrator) to a specific subset of users, groups, or devices.
For VIPs, executives, and IT admins, enable Restricted Management Administrative Units (IsMemberManagementRestricted = $true): even tenant-wide User Administrators cannot reset passwords or modify accounts inside an RMAU unless explicitly assigned inside that RMAU.
Create a Dynamic Regional Administrative Unit & Assign Scoped Helpdesk Role
Connect-MgGraph -Scopes "AdministrativeUnit.ReadWrite.All", "RoleManagement.ReadWrite.Directory"
# 1. Create a Dynamic Administrative Unit for APAC Users
$auBody = @{
DisplayName = "AU-Region-APAC-Users"
Description = "Dynamic Administrative Unit containing all active APAC users."
MembershipType = "Dynamic"
MembershipRule = '(user.country -in ["India", "Singapore", "Australia"]) and (user.accountEnabled -eq true)'
MembershipRuleProcessingState = "On"
}
$au = New-MgDirectoryAdministrativeUnit -BodyParameter $auBody
Write-Host "Created AU: $($au.DisplayName) ($($au.Id))" -ForegroundColor Green
# 2. Look up the Helpdesk Administrator Role Template ID
$helpdeskRole = Get-MgDirectoryRoleTemplate | Where-Object { $_.DisplayName -eq "Helpdesk Administrator" }
# 3. Assign a Scoped Role to the APAC Helpdesk Security Group (replace with your group ID)
$apacHelpdeskGroupId = "<APAC-HELPDESK-GROUP-OBJECT-ID>"
New-MgRoleManagementDirectoryRoleAssignment -BodyParameter @{
PrincipalId = $apacHelpdeskGroupId
RoleDefinitionId = $helpdeskRole.Id
DirectoryScopeId = "/administrativeUnits/$($au.Id)"
}
5. Automated Zero-Touch Offboarding (Leaver Runbook)
When an employee leaves (especially an involuntary termination), disabling the AD/Entra account alone is not enough—existing OAuth refresh tokens and active Exchange/Teams sessions can remain valid for up to 60 minutes unless explicitly revoked.
Run this standardized Graph PowerShell offboarding routine immediately upon termination:
param(
[Parameter(Mandatory)]
[string]$UserPrincipalName
)
Connect-MgGraph -Scopes "User.ReadWrite.All", "Directory.ReadWrite.All", "Group.ReadWrite.All"
$user = Get-MgUser -UserId $UserPrincipalName -Property Id, DisplayName, AssignedLicenses
# 1. Block sign-in immediately
Update-MgUser -UserId $user.Id -AccountEnabled:$false
Write-Host "[1/4] Sign-in blocked for $UserPrincipalName" -ForegroundColor Cyan
# 2. Revoke all active refresh tokens & browser/mobile sessions
Revoke-MgUserSignInSession -UserId $user.Id | Out-Null
Write-Host "[2/4] Active sign-in sessions revoked." -ForegroundColor Cyan
# 3. Remove from directly assigned (static) security groups
$memberOf = Get-MgUserMemberOf -UserId $user.Id -All
foreach ($obj in $memberOf) {
if ($obj.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.group') {
$groupTypes = $obj.AdditionalProperties.groupTypes
# Skip Dynamic groups (they auto-remove when AccountEnabled = false)
if (-not ($groupTypes -contains 'DynamicMembership')) {
try {
Remove-MgGroupMemberByRef -GroupId $obj.Id -DirectoryObjectId $user.Id -ErrorAction Stop
Write-Host " Removed from static group: $($obj.AdditionalProperties.displayName)" -ForegroundColor Gray
} catch {
Write-Warning " Skipped group $($obj.Id) (likely AD-synced or role-assignable): $($_.Exception.Message)"
}
}
}
}
Write-Host "[3/4] Static cloud group memberships cleaned." -ForegroundColor Cyan
# 4. Remove directly assigned licenses (if any exist outside group-based licensing)
if ($user.AssignedLicenses.Count -gt 0) {
$skuIds = $user.AssignedLicenses | ForEach-Object { $_.SkuId }
try {
Set-MgUserLicense -UserId $user.Id -AddLicenses @() -RemoveLicenses $skuIds -ErrorAction Stop
Write-Host "[4/4] Directly assigned licenses reclaimed." -ForegroundColor Green
} catch {
Write-Warning "Licenses are group-assigned and will auto-reclaim once dynamic group evaluation completes."
}
}
Chapter 2 Verification Checklist
Before advancing to Chapter 3 (Zero Trust Identity Security: Conditional Access, Passkeys & PIM), confirm these controls are in place:
- [ ] Every active member account has
UsageLocation,Department,EmployeeType, andCountrypopulated. - [ ] All license-bearing security groups use dynamic rules with
(user.accountEnabled -eq true). - [ ] Regional IT helpdesks are scoped via Administrative Units instead of tenant-wide directory roles.
- [ ] VIP/executive accounts are protected inside a Restricted Management Administrative Unit (RMAU).
- [ ] Your Leaver runbook calls
Revoke-MgUserSignInSessionimmediately after settingAccountEnabled = $false.
💬 Reader Comments & Feedback
Did this runbook help, or did Microsoft change a cmdlet or UI menu? Share your feedback below.
Leave a Comment or Report an Update