Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitManaging Administrative Units (AUs) in Microsoft 365 can be tricky—especially when you need to audit role assignments, verify scoping rules, or prepare for compliance checks. The AU list in the Microsoft 365 admin portal doesn’t always give you the full picture in a format you can easily work with.
This script solves that problem by exporting every AU in your tenant—including its unique Id, display name, and description—to a CSV file. Having AU IDs at hand makes it much easier to:
It’s simple, fast, and requires no advanced scripting—just connect, fetch, and export.
# Connect to Microsoft Graph (run once per session)
Connect-MgGraph -Scopes "AdministrativeUnit.Read.All","Directory.Read.All"
# Choose your output path (timestamped by default)
$OutputPath = ".\AdministrativeUnits_{0}.csv" -f (Get-Date -Format "yyyyMMdd_HHmmss")
# Fetch all AUs with selected properties
$aus = Get-MgDirectoryAdministrativeUnit -All -Property Id,DisplayName,Description
# Handle empty results gracefully
if (-not $aus) {
Write-Warning "No Administrative Units were found in the tenant."
$aus = @()
}
# Export to CSV (UTF-8)
$aus |
Select-Object Id, DisplayName, Description |
Export-Csv -Path $OutputPath -NoTypeInformation -Encoding UTF8
Write-Host "Export complete: $OutputPath"
Narrow by name:
Get-MgDirectoryAdministrativeUnit -Filter "startswith(displayName,'EMEA')" -ConsistencyLevel eventual
Broad matching across indexed fields:
Get-MgDirectoryAdministrativeUnit -Search '"marketing"' -ConsistencyLevel eventual
Add columns like Description, Visibility, etc.:
-Property Id,DisplayName,Description
Point to a reports folder:
$OutputPath = "D:\Reports\AdministrativeUnits_{0}.csv" -f (Get-Date -Format "yyyyMMdd_HHmmss")
Error | Cause | Solution |
---|---|---|
Authorization_RequestDenied / Insufficient privileges | Missing Graph permission/consent. | Connect with AdministrativeUnit.Read.All (or Directory.Read.All), accept consent, and re-run Connect-MgGraph. |
Request_UnsupportedQuery (with -Filter/-Search) | Unsupported property or malformed OData. | Use filterable props (e.g., displayName), keep filters simple (eq, startswith), or switch to -Search '"term"' with -ConsistencyLevel eventual. |
ResourceNotFound / 404 (when fetching a specific AU elsewhere) | Wrong AU Id or deleted AU. | List all AUs first and copy the correct Id. |
Partial results / paging issues | Not enumerating all pages. | Always include -All to auto-page through results. |
Empty CSV | No AUs match the query / tenant has none. | Remove filters or validate AU presence in the tenant. |
This minimalist script is ideal for quick inventories and baseline reporting of Administrative Units. The exported AU IDs are particularly useful for auditing, policy scoping, and automation scripting—areas where admin portals often fall short. It’s fast, readable, and easy to adapt—add filters, include more properties, or redirect the output path as needed.
© m365corner.com. All Rights Reserved. Design by HTML Codex