Große Postfächer in Microsoft 365 Tenant finden

Immer wieder haben User das Problem, dass ihr Microsoft 365 Postfach die maximale Größe (50 bzw. 100 GB) erreicht. Um mir regelmäßig einen Überblick verschaffen zu können, habe ich ein PowerShell-Script , das ich schon in einem älteren Posting erwähnt habe, so ergänzt, dass es mir eine sortierte Liste inkl. Lizenz und Archivstatus ausgibt:

DisplayName  UPN                  SizeGB   ItemCount  License             ArchiveEnabled


Aaaa Bbbb    aaaa.bbbb@firma.de   84,39    248211     E3                  No
Cccc Dddd    cccc.dddd@firma.de   45,08    46913      Business Standard   Yes
Eeee Ffff    eeee.ffff@firma.de   44,18    43080      Business Standard   No

Hier das dazugehörige PowerShell-Script:

Connect-ExchangeOnline
Connect-MgGraph -Scopes User.Read.All, Directory.Read.All

Get-EXOMailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox |
ForEach-Object {

$upn = $_.UserPrincipalName

# Mailbox Stats
$stats = Get-EXOMailboxStatistics -Identity $upn

# Lizenzdetails robust holen
$licenseDetails = Get-MgUserLicenseDetail -UserId $upn -ErrorAction SilentlyContinue
$licenseNames = $licenseDetails.SkuPartNumber

# Basismapping
$base = if ($licenseNames -contains "ENTERPRISEPACK" -or $licenseNames -contains "SPE_E3") {
"E3"
}
elseif ($licenseNames -contains "O365_BUSINESS_PREMIUM") {
"Business Standard"
}
elseif ($licenseNames -contains "O365_BUSINESS_ESSENTIALS") {
"Business Basic"
}
elseif ($licenseNames -contains "EXCHANGESTANDARD") {
"Exchange Online Plan 1"
}
elseif ($licenseNames -contains "EXCHANGEENTERPRISE") {
"Exchange Online Plan 2"
}
else {
$null
}

$license = if ($base) { $base } else { ($licenseNames -join ", ") }

# Archivstatus robust prüfen
$archiveStats = Get-EXOMailboxStatistics -Identity $upn -Archive -ErrorAction SilentlyContinue
$archiveEnabled = if ($archiveStats) { "Yes" } else { "No" }

[PSCustomObject]@{
DisplayName = $_.DisplayName
UPN = $upn
SizeGB = [math]::Round($stats.TotalItemSize.Value.ToBytes() / 1GB, 2)
ItemCount = $stats.ItemCount
License = $license
ArchiveEnabled = $archiveEnabled
}

} | Sort-Object SizeGB -Descending |
Format-Table DisplayName, UPN, SizeGB, ItemCount, License, ArchiveEnabled -AutoSize