Restoring a deleted Exchange 2010 mailbox from PowerShell

In our hosted Exchange 2010 SP1 environment we have to administer the environment via PowerShell, versus using the traditional Exchange Management Console (EMC) – one of the lovely limitations of using /hosting mode. Surprisingly, after almost a year of being in production this one had never come up until just yesterday: a user had been deleted (via Exchange Control Panel, which you can still thankfully use for end-user management) and their mailbox still sat on the server thanks to deleted mailbox retention. But how would I approach recovery

First, I needed to see what was out there from a recovery perspective. Thanks to Mike Pfeiffer’s blog post I was able to add his Get-DisconnectedMailbox function to my PowerShell profile by using the notepad $profile command. After a quick restart of the Exchange Management Shell (EMS) I ran the command and it easily gave me a list of all disconnected mailboxes across all of the databases, and I was able to confirm that the user’s mailbox was still there.

So the next challenge was, how can I do this all from PowerShell?

Hosting mode brings its own set of challenges, namely the lack of the familiarity a “point-and-click” environment provides. So after some digging I ran across ExchangeServerPro.com’s article on how to reconnect a deleted mailbox. Now while in the past I’ve been able to create a new AD user and reconnect the mailbox, to my delight it says that I can create a new restore request against a deleted mailbox against an active mailbox – and both can have the same name!

So I proceeded to run this wonderful command:

New-MailboxRestoreRequest -SourceDatabase Datastore1 -SourceStoreMailbox “End User” -TargetMailbox “End User”

But it failed with an error saying that the DN (distinguished name) did not match, and to use the AllowLegacyDNMismatch switch. Once I added it to the end of this command:

New-MailboxRestoreRequest -SourceDatabase Datastore1 -SourceStoreMailbox “End User” -TargetMailbox “End User” -AllowLegacyDNMismatch

The process started successfully, and after 10 minutes was completed. I logged into the user’s mailbox, and sure enough not only were the emails there but I noticed it even restored some of the shared mailbox folders. Impressive!

Chris Blackburn

Learn More →

One thought on “Restoring a deleted Exchange 2010 mailbox from PowerShell

  1. cefirod January 31, 2013 at 7:50 pm

    Thanks, i was stucked in the same parameter “allowedDNMistmatch” and looks like it works!

    Reply

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

css.php