Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitMailbox sprawl happens. A project ends, a shared mailbox lingers; a room gets repurposed, but its resource mailbox keeps receiving invites. Left unchecked, these stale mailboxes clutter address lists, confuse users, and complicate compliance. The good news: you can retire them cleanly with Remove-Mailbox—whether it’s a one-off cleanup or a bulk retirement from a CSV.
Note: While user mailbox creation/removal is typically handled automatically as users are provisioned/deprovisioned through Azure AD/Entra and licensing workflows, Graph PowerShell cannot be used to remove shared, room, and equipment mailboxes. For this, you need Exchange Powershell.
Remove-Mailbox -Identity <MailboxIdParameter> [-Permanent $true] [-Force] [-Confirm] [-WhatIf]
Key notes
Remove-Mailbox -Identity "test_shared"
Removes the test_shared mailbox (e.g., a shared mailbox). You’ll be prompted to confirm unless suppressed.
Remove-Mailbox -Identity "test_shared" -WhatIf
Shows the actions that would be taken—no changes are made.
CSV file (save as mailboxes-to-remove.csv):
Identity
marketing_shared
room-nyc-12a
equip-printer-4f
Script:
Connect-ExchangeOnline
$csvPath = "C:\Temp\mailboxes-to-remove.csv"
if (-not (Test-Path $csvPath)) { throw "CSV not found: $csvPath" }
$rows = Import-Csv -Path $csvPath
foreach ($r in $rows) {
$id = $r.Identity
if ([string]::IsNullOrWhiteSpace($id)) {
Write-Warning "Skipped a blank Identity row."
continue
}
try {
# Start safely: uncomment -WhatIf to preview; remove -WhatIf after validation
Remove-Mailbox -Identity $id -Confirm:$false
Write-Host "Removed mailbox: $id"
}
catch {
Write-Warning "Failed to remove '$id' — $($_.Exception.Message)"
}
}
Remove-Mailbox -Identity "marketing_shared" -Permanent $true
By setting -Permanent to $true, you delete the mailbox permanently, skipping the retention period typically offered for mailboxes.
Get-Mailbox -Identity | Format-List *
Get-MailboxPermission -Identity
Error | Cause | Solution |
---|---|---|
The term 'Remove-Mailbox' is not recognized | Not connected to Exchange Online module | Install/import EXO V3 module; run Connect-ExchangeOnline. |
Cannot find object 'XYZ' | Wrong Identity (alias/UPN/ID) or mailbox already removed | Verify with Get-Mailbox -Identity XYZ or list with Get-Mailbox. Check soft-deleted mailboxes. |
Insufficient permissions | Missing Exchange RBAC role | Use an account with Organization/Recipient Management roles. |
Deletion blocked by litigation hold / retention | Mailbox under hold/retention policy | Remove/adjust holds and retention first; involve compliance/legal before proceeding. |
Need irreversible removal | Soft-delete retains recoverability | Add -Permanent $true (only after approvals). |
Bulk script stops on one failure | Unhandled exception breaks loop | Use try/catch per row (as shown) so the script continues. |
Remove-Mailbox is the safest way to retire legacy mailboxes at scale while staying in control: preview with -WhatIf, use CSV-driven workflows, and respect compliance constraints like holds and retention. Keep in mind that Graph PowerShell doesn’t support mailbox deletion (shared/room/equipment)—use Exchange Online PowerShell for that, while user mailboxes generally follow your provisioning/deprovisioning lifecycle automatically. With clear process and a small dose of automation, your address lists stay clean, compliant, and easy to manage.
© m365corner.com. All Rights Reserved. Design by HTML Codex