Remove Duplicate Emails from an Office 365 Mailbox with PowerShell
Question details
Identify and remove thousands of duplicate email messages from an Office 365 mailbox after migration, preferably using PowerShell.
- Product
- Microsoft 365 Exchange Online
- Device & OS
- not provided
- Scenario
- A mailbox has been migrated to Office 365, and the user wants an efficient way to clean up duplicate messages.
- Observed behavior
- Thousands of duplicate emails appeared in the mailbox after migration.
Confirm which mailbox and folders contain duplicates, and make sure you have permission to access them. Test any cleanup method on a small set of messages before applying it to the full mailbox.
Find Duplicate Candidates with Microsoft Graph PowerShell
Use this read-only approach to identify likely duplicates in the Inbox before deciding which messages to remove.
Messages with the same Internet Message ID are duplicate candidates, not necessarily copies that should always be deleted. This example checks only the Inbox and does not remove any messages.
In PowerShell, run Install-Module Microsoft.Graph -Scope CurrentUser, then run Connect-MgGraph -Scopes "Mail.Read" and sign in with an account authorized to read the mailbox. Consent may require an administrator.
Replace user@example.com with the mailbox address and run: $messages = Get-MgUserMailFolderMessage -UserId "user@example.com" -MailFolderId "inbox" -All -Property "id,internetMessageId,subject,receivedDateTime".
Run: $messages | Where-Object { $_.InternetMessageId } | Group-Object InternetMessageId | Where-Object { $_.Count -gt 1 } | ForEach-Object { $_.Group } | Select-Object Id,InternetMessageId,Subject,ReceivedDateTime | Export-Csv -Path ./duplicate-candidates.csv -NoTypeInformation.
Open duplicate-candidates.csv and compare the listed messages in Outlook or Outlook on the web. Delete only confirmed extra copies, keeping the message you want to retain.

Use a Reviewed PowerShell Deduplication Script for Bulk Cleanup
For thousands of confirmed duplicates, use a maintained script that supports Exchange Online and provides a preview or report before deletion.
Review Mailbox Cleanup Reports with WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and Microsoft Office format compatibility for seamless migration. Use WPS Spreadsheets to review exported cleanup reports; WPS Office does not remove duplicate emails from Exchange Online.

Frequently Asked Questions
Does the PowerShell report delete any emails?
No. The Microsoft Graph commands shown retrieve Inbox message details and export duplicate candidates to a CSV file. They do not delete messages.
Are messages with the same Internet Message ID always safe to delete?
No. Compare the messages in Outlook or Outlook on the web before deleting extra copies. The ID is a useful matching signal, but it does not establish which copy you should keep.
Does the Inbox scan include subfolders?
No. The example uses the inbox folder ID and checks that folder only. Other affected folders need to be checked separately.
Can I still use the old TechNet duplicate-removal script?
Check whether the script is still available and supports current Exchange Online authentication. Review its code and test its preview on a small set before using any deletion option.
Can WPS Office remove duplicates from my mailbox?
No. Use Microsoft Graph PowerShell or a reviewed Exchange Online cleanup tool for mailbox removal. WPS Spreadsheets can help you inspect an exported CSV report.




