Role-assignable security groups are a clean way to manage Entra ID (Azure AD) admin role assignments at scale—especially when you want consistent, repeatable role assignment across multiple groups without manually creating and wiring each one.
This script bulk-creates role-assignable security groups and assigns the Authentication Administrator role to each group.
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
# Number of groups to create
$GroupCount = 10
# Prefix for group names
$GroupNamePrefix = "AUTH-Role-Group"
# Get Global Administrator role
$GlobalAdminRole = Get-MgDirectoryRole | Where-Object {
$_.DisplayName -eq "Authentication Administrator"
}
# If role is not activated, activate it
if (-not $GlobalAdminRole) {
$RoleTemplate = Get-MgDirectoryRoleTemplate | Where-Object {
$_.DisplayName -eq "Authentication Administrator"
}
Enable-MgDirectoryRole -DirectoryRoleTemplateId $RoleTemplate.Id
Start-Sleep -Seconds 5
$GlobalAdminRole = Get-MgDirectoryRole | Where-Object {
$_.DisplayName -eq "Authentication Administrator"
}
}
Write-Host "Authentication Administrator ID:" $GlobalAdminRole.Id
for ($i = 1; $i -le $GroupCount; $i++) {
$GroupName = "$GroupNamePrefix-$i"
Write-Host "Creating group: $GroupName"
# Create role-assignable group
$Group = New-MgGroup -BodyParameter @{
displayName = $GroupName
description = "Role-assignable group with Authentication Administrator permissions"
mailEnabled = $false
mailNickname = ($GroupName -replace '\s','').ToLower()
securityEnabled = $true
isAssignableToRole = $true
}
# Assign Authentication Administrator role to the group
New-MgDirectoryRoleMemberByRef `
-DirectoryRoleId $GlobalAdminRole.Id `
-BodyParameter @{
"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/$($Group.Id)"
}
Write-Host "Assigned Authentication Administrator role to $GroupName"
}
Write-Host "Completed creation and role assignment for $GroupCount groups."
The script checks your tenant’s activated directory roles using:
If the role is already activated in the tenant, the script proceeds.
If the role is not activated, the script:
For each iteration:
Immediately after creating the group, the script assigns the role to the group using:
The script uses Write-Host throughout so you can track:
If you want to evolve this into a more “production-ready” bulk provisioning script, here are some practical upgrades you can consider:
| Error | Cause | Solution |
|---|---|---|
| Insufficient privileges / Access denied | Insufficient privileges to complete the operation | Connect with an account that has the required Entra roles/permissions. In most environments, role management actions require elevated admin privileges. |
| Role template or role not found: $RoleTemplate is empty or role never resolves after enabling |
The role display name doesn’t match exactly, or role activation hasn’t propagated yet. | Confirm the role display name is correct in your tenant and allow a bit more time after enabling. (The script already includes a 5-second delay.) |
| Request_BadRequest when creating the group | Common reasons include:
|
Verify role-assignable group support is available and that your admin context is permitted to create them. |
| Role assignment fails for the group Role member reference add fails via New-MgDirectoryRoleMemberByRef |
The role isn’t properly activated, or the role assignment operation is blocked by permission/scoping constraints. | Confirm the role ID printed by the script is valid and that your session has role management rights. |
If you’re managing admin access at scale, role-assignable security groups are one of the cleanest ways to standardize access without manually assigning roles to individual users every time. This script helps you rapidly provision multiple role-assignable groups and immediately assign the Authentication Administrator role to each—making it ideal for larger environments, access segmentation, or tiered admin models.
© m365corner.com. All Rights Reserved. Design by HTML Codex