Exchange 2010: Remove disconnected mailbox

After you delete a user from Acrive directory or Exchagne their mailbox is kept in the Exchange database for a number of days until it is automatiaccly removed. As defined in the “Limits” section of the database properties.

If you want to force the removal of the disconnected mailbox to free up space within your mailbox database, you can do so with the following powershell functions.

Save the following as Disconnected-Mailboxes.ps1

function Get-DisconnectedMailbox {
    [CmdletBinding()]
    param(
        [Parameter(Position=0, Mandatory=$false)]
        [System.String]
        $Name = '*'
    )

    $mailboxes = Get-MailboxServer
    $mailboxes | %{
        $disconn = Get-Mailboxstatistics -Server $_.name | ?{ $_.DisconnectDate -ne $null }
        $disconn | ?{$_.displayname -like $Name} | sort -Property DisplayName |
            Select DisplayName,
            @{n="Identity";e={$_.MailboxGuid}},
            Database,@{n="MailboxState";e={$_.DisconnectReason}},TotalItemSize
    }
}

function Remove-DisconnectedMailbox {
    [CmdletBinding(SupportsShouldProcess=$true)]
    param(
        [Parameter(Position=0, ValueFromPipelineByPropertyName=$true, Mandatory=$true)]
        [System.String]
        $Identity,
        [Parameter(Position=1, ValueFromPipelineByPropertyName=$true, Mandatory=$true)]
        [System.String]
        $Database,
	[Parameter(Position=2, ValueFromPipelineByPropertyName=$true, Mandatory=$true)]
        [System.String]
        $MailboxState
        )

    process {
        Remove-StoreMailbox @PSBoundParameters
    }
}

These two functions will list all the disconnected mailboxes, and delete disconnected mailboxes.

See Here to find out how to import functions into Power Shell

Get-DisconnectedMailbox
This function will list all the disconnected mailboxes

Remove-DisconnectedMailbox
This function will remove a disconnected mailbox

To remove all disconnected mailboxes, run this command

Get-DisconnectedMailbox | Remove-DisconnectedMailbox