Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitAdministrative Units (AUs) help you scope administration in Microsoft Entra ID. When an AU is no longer needed, you can remove it safely with Remove-MgDirectoryAdministrativeUnit . Deleting an AU does not delete the users, groups, or devices inside it; it only removes the AU container and its scoped relationships.
Remove-MgDirectoryAdministrativeUnit -AdministrativeUnitId <String>
$administrativeUnitId = "00000000-0000-0000-0000-000000000000"
# Remove without extra prompts
Remove-MgDirectoryAdministrativeUnit -AdministrativeUnitId $administrativeUnitId
Tip: If you want a dry-run first, add -WhatIf.
Save as aus-to-remove.csv:
AdministrativeUnitId
11111111-1111-1111-1111-111111111111
22222222-2222-2222-2222-222222222222
33333333-3333-3333-3333-333333333333
$csvPath = "C:\temp\aus-to-remove.csv"
if (-not (Test-Path $csvPath)) { throw "CSV not found at $csvPath" }
$rows = Import-Csv -Path $csvPath
foreach ($row in $rows) {
$auId = $row.AdministrativeUnitId.Trim()
if ([string]::IsNullOrWhiteSpace($auId)) {
Write-Warning "Skipped a row with empty AdministrativeUnitId."
continue
}
try {
Remove-MgDirectoryAdministrativeUnit -AdministrativeUnitId $auId -Confirm:$false
Write-Host "Removed AU: $auId"
}
catch {
Write-Warning "Failed to remove AU '$auId'. Error: $($_.Exception.Message)"
}
}
Make your life easier by keeping one AU ID per line under the AdministrativeUnitId header.
$au = Get-MgDirectoryAdministrativeUnit -Filter "displayName eq 'Sales Team AU'"
$au.Id
Error | Cause | Solution |
---|---|---|
Authorization_RequestDenied or Insufficient privileges to complete the operation | Missing AdministrativeUnit.ReadWrite.All or consent not granted | Reconnect with the correct scope or have an admin grant consent (delegated or app-only). |
Request_ResourceNotFound / Resource not found | AU ID doesn’t exist (typo, already deleted) | Verify the AU ID. In bulk deletes, continue past missing IDs; optionally pre-validate with Get-MgDirectoryAdministrativeUnit. |
Forbidden | Caller lacks rights on this AU (scoped admin scenario) | Use an account/app with rights scoped to that AU or elevate permissions appropriately. |
PreconditionFailed (412) when using -IfMatch | ETag mismatch due to concurrent change | Refresh the AU, get the latest ETag, and retry; or omit -IfMatch if you don’t need concurrency safeguards. |
Throttling / intermittent failures | Service limits hit during bulk deletion | Add small delays or retry logic with backoff in your loop. |
Remove-MgDirectoryAdministrativeUnit gives you a fast, predictable way to retire AUs you no longer need—without touching the underlying users, groups, or devices. Start with a single AU removal when testing; then use the CSV-driven bulk pattern to clean up at scale. Add -WhatIf for safety, ensure the right permissions, and you’ll have an efficient AU lifecycle management in place.
© m365corner.com. All Rights Reserved. Design by HTML Codex