When you disable or remove a mailbox from a user the mailbox then goes into a “Disconnected Mailbox” folder. If you’re low on space and you know you won’t need to recover or re-attach these mailboxes for any reason you can purge them out of Exchange completely.
For this you do need to specify the Mailbox Database:
Get-MailboxDatabase
This will return something like this:
Name Server Recovery ReplicationType
—- —— ——– —————
Mailbox Database 1318916598 EXCHANGE False None
Now query Exchange to find the disconnected mailboxes:
Get-MailboxStatistics -Database “mailbox database 1318916598” | FL *name,identity,*disconnect*
This should return a parsed display of every mailbox. The only ones you’re interested in have a DisconnectReason : Disabled
If you only want a list of Disabled mailboxes:
Get-MailboxStatistics -Database “mailbox database 1318916598” | where {$_.DisconnectReason -eq “disconnected”}
If the list looks right now you can safely delete these mailboxes.
You can only delete mailboxes using the -Identity of each mailbox which is a big long hexadecimal string: 5f320ec4-ce9a-4bf2-94c9-9b4f9fe4ed2b
Get-MailboxStatistics -Database “mailbox database 1318916598” | where {$_.DisconnectReason -eq “disconnected”} | FL Identity
This will return back a list of the identities of all mailboxes in a disabled state.
Identity : 34551c26-e387-4eb7-94a7-b4df33be7a06
Identity : 127545f4-17cf-48e7-bbe6-bc4cf999930a
Identity : b065f3a2-e9f9-4c90-aee0-c2c67bbfe4ea
Identity : d1e00409-d84f-4491-a57c-c474dc653621
Identity : 6cb4d4dd-358f-426b-96cd-c6c576022700
Identity : 801a5fd1-b3fc-4e08-9b9a-d526256e70ba
Identity : fc0ab92d-c101-467b-91f9-e137ed625cc1
The problem with this is this output is not formatted in a way that can be fed into the command that will delete the mailboxes permanently:
Remove-StoreMailbox -Database “mailbox database 1318916598” -Identity “fc0ab92d-c101-467b-91f9-e137ed625cc1” -MailboxState Disabled -Confirm:$false
So you can either do this one at a time which would be quite time consuming or find a way to script this.
Get-MailboxStatistics -Database “mailbox database 1318916598” | where {$_.DisconnectReason -eq “Disabled”} | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState Disabled}
This will prompt for each mailbox to be deleted and I found on the Exchange server I applied this to the identities were all correct but the server would trip over the first 13 or so entries and give a stupid error: Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
You could probably at least get the mailboxes to delete that do not throw up this error by adding -Confirm:$false to the end of the line.
I ended up removing the remaining mailboxes individually.
I found another poster who’s examples showed a way to break up the commands:
$Mailboxes = Get-MailboxStatistics –Database “mailbox database 1318916598” | Where-Object {$_.DisconnectReason –eq “Disabled”}
$Mailboxes | ForEach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState Disabled -Confirm:$False}
It would eliminate the error but it makes more sense to put this into a script ‘RemoveDisabledMailboxes.PS1″
The error is irritating because that command comes directly from Microsoft and because it only skips over the first number of entries but works successfully on what’s remaining. It just cannot ever get the first 13 or so entries.