Reset Exchange Online migration

Problem

  • There is a botched or aborted mail migration Exchange Online
  • The mail migration must be re-planned and “reset” 
  • No time to wait for EXO mailboxes to be deleted after 30 days
  • How to “reset” existing EXO mailboxes?
    • Reset = delete all mail, folders, sub-folders, calendar entries, clean out the purged items and recoverable items folder, etc. Squeaky clean mailboxes

Solution

  • Here are two PowerShell scripts, one from Aaron Guilmett of undocumentedfeatures.com fame which performs the cleanup and my helper script which automates running the cleanup script against multiple mailboxes via a CSV and logs all steps to C:\Temp 
  • Wipe-ExchangeOnlineMailbox.ps1 from Aaron Guilmett 
  • Wipe-ExchangeOnlineMailbox-Helper.ps1 from me
    • Put both scripts in the same folder, configure the helper script with usernames log paths, and a one column CSV of EXO mail addresses and run it
    • NOW WOULD BE A GOOD TIME TO READ MY DISCLAIMER BELOW. THESE SCRIPTS WILL PERMANENTLY AND IRREVOCABLY DELETE A TARGET MAILBOXES’ EMAILS, CALENDAR ENTRIES, ETC… THIS INCLUDES YOUR BOSSES’ MAILS IF YOU TARGET THE WRONG MAILBOX!
A view of a BitTitan MigrationWiz portal

More Details

As part of a customer migration using BitTitan MigrationWiz, I had the problem of having to roll back the first migration, but I had to do this rollback within 3 weeks.  

The problem with BitTitan’s MigrationWiz and other third-party mail migration solutions is that you have three choices:  

  1. Keep the already migrated data from the “failed” migration in the mailbox and hope that the users being migrated do not delete or move a bunch of mail in their source mailboxes in the meantime, as this will confuse MigrationWiz and may cause duplicate mails / data in the destination mailboxes
  2. If one completely deletes the MS365 user accounts, Exchange Online waits 30 days to completely delete said mailboxes via the Microsoft backend processes, and only after that could recreate “clean” mailboxes
  3. Magically empty the mailboxes completely without deleting the accounts or mailboxes themselves 

Normally I would recommend option 2, but due to the time constraints of the project I could not wait 30 days. 

The script by Aaron hosted on TechNet does this “emptying” of an Exchange Online mailbox, so I was able to do the third option. This script first deletes all subfolders, which completes much of the cleanup process, but then uses the now-deprecated, but still functional as of 03.03.2023, Search-Mailbox PowerShell command for the final cleanup of all remaining data. Although this command is technically obsolete from Microsoft, it fortunately still seems to work. There is a replacement for this command, New-ComplianceSearch, but this command can only delete 10 items at a time and therefore cannot be used to “reset” an Exchange Online mailbox.  

More info and resources

Here are the URLs for the project and for the post in the PowerShell Gallery:  

An animated GIF of the PowerShell script wiping an Exchange mailbox
Look at that beautiful logging and error reporting.

Conclusion

I changed the script a bit to read in a CSV file so it would only hit the right mailboxes. I was deleting about 1GB per hour and needed a few passes before I was 100% sure nothing was being skipped. Eventually it worked, and after the second migration no users complained about duplicate content in their mailboxes.  If something like this has happened to you, please let me know and if I can help, I will!

Leave a Reply

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