Knowledge BaseHow do i merge SoftDeleted Office 365 mailbox into an active one
Andrey Staff asked 6 years ago

Need to recover SoftDeleted Office 365 mailbox

1 Answers
Andrey Staff answered 6 years ago

Step 1: Open PowerShell ISE As Administrator

Right click on PowerShell and run ISE as Administrator

Step 2: Copy the script below into the script pane in ISE

#Connect to Office 365
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
# List the Soft Deleted Mailboxs and pick the one that needs to be imported
$DeletedMailbox = Get-Mailbox -SoftDeletedMailbox | Select DisplayName,ExchangeGuid,PrimarySmtpAddress,ArchiveStatus,DistinguishedName | Out-GridView -Title “Select Mailbox and GUID” -PassThru
# Get Target Mailbox
$MergeMailboxTo = Get-Mailbox | Select Name,PrimarySmtpAddress,DistinguishedName | Out-GridView -Title “Select the mailbox to merge the deleted mailbox to” -PassThru
# Run the Merge Command
New-MailboxRestoreRequest -SourceMailbox $DeletedMailbox.DistinguishedName -TargetMailbox $MergeMailboxTo.PrimarySmtpAddress -AllowLegacyDNMismatch
# View the progress
#Grab the restore ID for the one you want progress on.
$RestoreProgress = Get-MailboxRestoreRequest | Select Name,TargetMailbox,Status,RequestGuid | Out-GridView -Title “Restore Request List” -PassThru
# Get the progress in Percent complete
Get-MailboxRestoreRequestStatistics -Identity $RestoreProgress.RequestGuid | Select Name,StatusDetail,TargetAlias,PercentComplete

Step 3: Click The Green Play Button

Play the script and enter / choose the following
1st prompt is your global admin creds for your Office 365 tenant
2nd prompt will show you the list of Soft Deleted Mailboxes- Choose the one you want and hit Ok
3rd prompt is the list of live mailboxes you can import / merge that soft deleted mailbox to – choose the one you want and hit Ok
4th prompt is the list of current merges taking place – choose the one you want progress on and hit ok
last display will be the progress on the merge you chose, copy and paste the command into the window and just run it when you need to see where the percentcomplete is.

Step 4: Option To Import To A Single Folder

When you run this merge command it will reimport the emails to the various folders, (inbox,sent items,etc) just as if you ran a PST import. There is a command switch that will allow you to import this mailbox into a single folder with the various folders under that. You would need to modify the merge command at the end and add the -TargetFolder WhaeverFolderName and it will import all the stuff into that folder.