Sunday, August 30, 2015

[EX2010] Delete Disconnected Mailboxes



Update the databases to show all disconnected mailboxes
Get-MailboxDatabase | Clean-MailboxDatabase


List all disconnected mailboxes in a database and display DisconnectReason if its SoftDeleted or Disabled
Get-MailboxStatistics -Database DATABASE | Where-Object {$_.DisconnectDate -Notlike $NULL} | ft DisplayName, DisconnectDate, MailboxGuid, DisconnectReason –Wrap


Remove all SoftDeleted disconnected mailboxes from a Database
Get-MailboxStatistics -Database DATABASE | where {$_.DisconnectReason -eq "SoftDeleted"} | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}


* Note you will be prompted to confirm each deletion, type Y to each confirmation as prompted. You can add the -Confirm switch to bypass confirmation prompt.