Removing disconnected mailboxes in Exchange Server 2007

Article Source

Description: Removes a given user from AD and disconnects their Mailbox
Comamnd: Remove-Mailbox -Identity contoso\john

Description: Removes a given user from AD and purges their mailbox from the database
Command: Remove-Mailbox -Identity contoso\john -Permanent $true

Description:Purges from the database a single already disconnected mailbox. Uses Get-MailboxStatistics to get the identity of the user before passing to remove-mailbox
Command: $Temp = Get-MailboxStatistics | Where {$_.DisplayName -eq 'John Peoples'}
Remove-mailbox -Database Server01\Database01 -StoreMailboxIdentity $Temp.MailboxGuid

Description:Removes all disconnected Mailboxes from a Database
Command: Get-MailboxStatistics -database "server\database" | where {$_.disconnectdate -ne $null} | foreach {Remove-mailbox -database $_.database -storemailboxidentity $_.mailboxguid}

Addtional Info - Article Source

Exchange Server 2007 doesn't allow us to purge the disconnected mailbox. In order to remove one or multiple disconnected mailboxes we can be performing these steps:

Listing all disconnected mailboxes

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

Removing a single entry

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

Removing all users at the same time

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

Now that we have all disconnected mailboxes in a var, we can run the following cmdlet to remove all of them:

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