A service principal can receive a Microsoft Entra role scoped to an administrative unit, but AdministrativeUnit.ReadWrite.All and the other Microsoft Graph application permissions required by this workflow cannot themselves be restricted to one AU. ^1^
Consequently, a fully unattended app can perform the workflow, but Microsoft Entra cannot enforce the target AU as the authorization boundary for every operation. The application must enforce that boundary itself.
Recommended app-only configuration
Grant only the application permissions required by the operations you implement:
| Operation |
Least-privileged application permission |
AU-scoped? |
| Invite a guest |
User.Invite.All |
No. Invitation creates the guest in the tenant; it does not place the guest in an AU. B2B invitations must also be enabled. ^2^ |
| Add an existing guest to the AU |
AdministrativeUnit.ReadWrite.All |
No. This application permission can modify AU membership tenant-wide. ^3^ |
| Create a group directly in the AU |
Group.Create + AdministrativeUnit.Read.All |
Requires either Groups Administrator or User Administrator assigned to the service principal at that AU, plus directory-read access. ^3^ |
| Add the guest to the group |
GroupMember.ReadWrite.All |
No; the application permission can modify eligible groups throughout the tenant. ^4^ |
| Delete the guest account |
User.ReadWrite.All |
No; it can delete nonprivileged users outside the AU as well. Extra role privilege is required for users holding privileged administrative roles. ^5^ |
For direct group creation under the AU endpoint, choose Groups Administrator unless the app also needs AU-scoped user-administration capabilities. Do not add User Administrator merely for group creation, because either role satisfies that API’s role requirement.
The service principal also needs directory-read access. Microsoft documents that service principals do not receive directory-read permissions by default and that these read permissions cannot currently be scoped to an AU. Assign tenant-scoped Directory Readers, or grant an appropriate Graph read application permission such as Directory.Read.All. ^6^
Assign the AU-scoped role
Prerequisites:
- Microsoft Entra PowerShell installed.
- A Privileged Role Administrator executing the assignment.
- Microsoft Entra ID P1 or P2 for the administrative-unit administrator assignment; AU members require Microsoft Entra ID Free. ^7^
Connect-Entra -Scopes 'Application.Read.All',
'AdministrativeUnit.Read.All',
'RoleManagement.ReadWrite.Directory'
$sp = Get-EntraServicePrincipal -Filter "DisplayName eq 'My Application'"
$au = Get-EntraAdministrativeUnit -Filter "DisplayName eq 'My Admin Unit'"
$role = Get-EntraDirectoryRoleDefinition `
-Filter "DisplayName eq 'Groups Administrator'"
New-EntraDirectoryRoleAssignment `
-PrincipalId $sp.Id `
-RoleDefinitionId $role.Id `
-DirectoryScopeId "/administrativeUnits/$($au.Id)"
Microsoft Entra supports assigning AU-scoped roles to service principals. ^1^
This script assigns the Entra role only. It does not add Microsoft Graph application permissions or grant admin consent; configure those separately on Entra ID → App registrations → your app → API permissions.
End-to-end API sequence
-
POST /invitations using User.Invite.All; retain the returned guest user ID.
-
POST /directory/administrativeUnits/{au-id}/members/$ref to add that guest ID to the AU.
-
POST /directory/administrativeUnits/{au-id}/members to create the group directly within the AU.
-
POST /groups/{group-id}/members/$ref to add the guest to the group.
- When offboarding, remove group/AU memberships as needed, then optionally call
DELETE /users/{guest-id}.
Adding a group to an AU scopes management of the group object, not the users in that group. Users must be added directly to the AU when their user objects need AU-scoped administration. ^7^
Deletion warning: DELETE /users/{guest-id} is destructive and can affect access, ownership, licenses, and downstream resources. Before automation, verify the tenant and immutable guest object ID, check ownership/dependencies, log the operation, and preferably require approval.
Security boundary
The app should maintain an allowlist containing the permitted AU ID and group IDs, reject arbitrary object IDs, and verify AU membership before updates or deletion. However, these checks are defense in depth—not a Microsoft Entra authorization boundary. A compromised credential carrying AdministrativeUnit.ReadWrite.All, GroupMember.ReadWrite.All, or User.ReadWrite.All remains technically capable of operations elsewhere in the tenant.
A delegated design can enforce AU-scoped Entra roles for operations that honor those roles, but it does not make guest invitation AU-scoped and does not automatically constrain operations independently authorized by tenant-wide Graph permissions.
References
- Manage roles
- Create invitation
- Add a member
- Add members
- Delete a user
- Assign Microsoft Entra roles
- Administrative units in Microsoft Entra ID