Saturday, February 28, 2009

Remove Disconnected Mailboxes In Exchange

Removing Disconnected mailboxes in exchange is now a multi-step process.  The first part is to get a listing of the disconnected mailboxes so that the GUID of it can be obtained.  Then, using this GUID and the name of the mailbox database, the second command is then executed to actually remove the mailbox

To list all disconnected mailboxes, issue the following  command into the command shell:

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

Then to actually remove the mailb0x issue:

Remove-Mailbox -Database -StoreMailboxIdentity -confirm:$false

If you wish to remove all disconnected mailboxes at the same time, issue the following from the command shell to get a list of all users:

$users = Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid

Next issue the following to remove all:

$users | ForEach { Remove-Mailbox -Database "Mailbox Database" -StoreMailboxIdentity $_.MailboxGuid -confirm:$false }

No comments: