Monday, January 11, 2016

Deleting Mailbox Database in Multiforest Domain

Hi folks,

I would love to share my first Exchange adventure that I had in 2016. I needed to remove a mailbox database from the 2013 mailbox server that won't host mailboxes.

I have removed all kinds of the mailboxes from the database by moving them to another database. For details you can read this article as it's not worthy of time to go into the details which are already recorded and published. To make sure that nothing is left on the DB I have even retrieved all the soft deleted mailboxes (result of removal or move of mailbox to the other DB) by using this command:

Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq "SoftDeleted" } | ft DisplayName,Database,MailboxGuid -AutoSize

I removed them by running the following command against each Mailbox GUID:

Remove-StoreMailbox -Identity XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX -Confirm:$false -Database DB001 -MailboxState SoftDeleted

But when running Remove-MailboxDatabase I was greeted by the following error:

Scratching my head lead me to remember that my AD forest has more than one domain with mailboxes. It lead me to this thread which contained a magic silver bullet to resolve this issue. All I needed to do is to run the following command:

Set-ADServerSettings -ViewEntireForest:$true

This allows to see mailboxes in the whole forest instead of only AD domain where Exchange servers are located. After connecting my PowerShell session to the whole forest I could retrieve mailboxes in the database by running and moving them to another DB:

Get-Mailbox -Database DB001|New-MoveRequest -TargetDatabase DB003

After all move requests have been successfully completed I removed them and removing mailbox DB was successful after I ran:

Remove-MailboxDatabase DB001 -Confirm:$false