Sunday, April 12, 2009

How to remove disconnected mailboxes in Exchange Server 2007

How to remove disconnected mailboxes in Exchange Server 2007
If you are lookin for a way how to purge disconnected mailbox from Exchange 2007 from Exchange Management Console you in for a big surprise because only way to do it is by using shell. Exchange Server 2007 doesn't allow you to purge the disconnected mailbox and in order to remove single or multiple disconnected mailboxes you can do following:

Get all disconnected mailboxes
Get-MailboxStatistics where-object { $_.DisconnectDate -ne $null } Select DisplayName,MailboxGuid

Remove a single disconnected mailbox
Remove-Mailbox -Database -StoreMailboxIdentity -confirm:$false

Remove all disconnected mailboxes
$users = Get-MailboxStatistics where-object { $_.DisconnectDate -ne $null } Select DisplayName,MailboxGuid,Database

Now, all disconnected mailboxes are in a variable and you need to run following cmdlet to remove all of them:
$users ForEach { Remove-Mailbox -Database $_.Database -StoreMailboxIdentity $_.MailboxGuid -confirm:$false }

No comments: