How to Restore a Deleted Mailbox with PowerShell
There’s one important key to remember
No matter how you accidentally deleted a person’s mailbox in Exchange, you can probably restore it using PowerShell (PoSh). The key is doing it as soon as you realize the mailbox has been deleted.
It’s a heart-jumped-into-my-throat moment when we realize we’ve accidentally done this. If you’ve only deleted a few email messages, we can show youhow to recover deleted emails in Office 365too.
Before we begin, note that this is meant for restoring deleted mailboxes inExchange Onlinefor the Office 365 environment andExchange 2010. We’re also assuming that you have the administrative rights to use the methods described and have done somebasic PowerShell scripting.
What Happens When a Mailbox Is Deleted?
The mailbox gets moved to either theAzure Active Directory(AD) recycle bin in Exchange Online or theDisconnected Mailboxesdirectory in Exchange 2010.
It may sit there for up to 30 days depending on the retention policies that are in place. That gives us a grace period to recognize our mistake and recover from it.
Restore a Deleted Mailbox In Exchange Online
In your local session, open the Powershell console and use the following command to set your login credentials into the variable.
This makes it easier to work with other scripts later on.
A window will open where you can enter your username and password for managing Exchange Online.
Next, set the execution policy level so that we can actually do things in our session. This allows us to run our unsigned commands. But you may want to learnbest practices for signing PowerShell scriptstoo.
When prompted, pressYfor Yes.
Now we’ll create the variable$sessionto be used to open a connection between the local computer and Exchange Online.
Powershell-liveidis the id of your Office site. Usually this is some variation of your company’s name.
Use the following command to open a PoSh session on Exchange Online:
Now we’re working with PowerShell directly in Exchange Online, even though we’re sitting at our own computer.
The next part is super easy. Making the connection will have taken us far longer.
All we have to do is run the cmdlet shown below:
Change both instances ofuser@mycompany.comto the appropriate mailbox name and Windows LiveID of the mailbox we want to restore. Note that they may not be the same.
We also have to set a new password for the mailbox. Changenewpasswordin the script to the password of your choice. You’ll need to relay that to the user and ask them to change their password the next time they log in.
Finally, use the next cmdlet to check to make sure that this worked.
If it has been restored, the cmdlet will return information about the restored mailbox. If it returns an error, go through the commands again and ensure that the correct mailbox and Windows LiveID are being used.
If that still doesn’t work, then we’ll need to restore the mailbox from a system backup. There’s many types of system backups, so that’s beyond the scope of what we’re doing today.
When we’re done, we must close the PoSh session. The number of PoSh sessions we have running is limited. Leaving it open uses one of those sessions. Unless we close it, we’ll have to wait for the session to time-out before we can start another one.
That’s it. You may even want to script this into a PowerShell Module for ease of use if it happens again.
This doesn’t work for Office 365 or hybrid environments. It only works for Exchange 2010 on-premises.
On the mail server, open theExchange Management Console(EMC).
Navigate toRecipient Configuration>Disconnected Mailbox. We should see the user’s mailbox there.
If we don’t, then the mailbox database cleaning process hasn’t happened yet. That’s OK, we can force it.
Check it to make sure all the settings are correct, like e-mail address and alias. If it looks good, the next time the user opens their Outlook, everything will be there just as it was.
Mailbox Restored
That’s how to use PowerShell to restore mailboxes in Exchange Online and Exchange 2010. If you’ve got a hybrid environment, it’s a bit more complicated but it can be done.
Just knowing that these different cmdlets exists puts you in a good position to work with Exchange, no matter what version or configuration.
Guy has been published online and in print newspapers, nominated for writing awards, and cited in scholarly papers due to his ability to speak tech to anyone, but still prefers analog watches.Read Guy’s Full Bio
Leave a Reply
Your email address will not be published.Required fields are marked*
Comment*
Name*
Email*
Website
Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.
HomeAbout UsEditorial StandardsContact UsTerms of Use
Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved