Task 3 – Delete All Disconnected Mailboxes Across All Exchange 2007 Mailbox Servers…

In my previous article, I have explained in detail how to get a list of all disconnected mailboxes across all mailbox servers in your organization. As Exchange 2007 doesn’t give us the option to delete the disconnected mailboxes using the console, we need to know the cmdlets to purge the mailboxes. So, for a large…

In my previous article, I have explained in detail how to get a list of all disconnected mailboxes across all mailbox servers in your organization. As Exchange 2007 doesn’t give us the option to delete the disconnected mailboxes using the console, we need to know the cmdlets to purge the mailboxes.

So, for a large enterprise with many mailbox servers, the following command can be run from a management server to list all the disconnected mailboxes.

Get-ExchangeServer | Where-Object {$_.IsMailboxServer –eq $true} | ForEach-Object { Get-MailboxStatistics –Server $_.Name | Where-Object {$_.DisconnectDate –notlike ‘’}}

In order to delete the mailboxes, lets first store all disconnected mailboxes in a variable $mailboxes with the properties that we need. After that, we need to pipe the variable into a loop to delete all disconnected mailboxes.

$mailboxes = Get-ExchangeServer | Where-Object {$_.IsMailboxServer –eq $true} | ForEach-Object { Get-MailboxStatistics –Server $_.Name | Where-Object {$_.DisconnectDate –notlike ‘’}} | select displayname, mailboxguid, database

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

For a smaller shop, command can be made a bit more simple.

$mailboxes = Get-MailboxStatistics | where-object { $_.DisconnectDate –notlike ‘’ } | Select displayname, mailboxguid, database

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

2 Comments

  1. Rajith Jose Enchiparambil says:

    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *