Email Migration

Remove Duplicate Emails from an Office 365 Mailbox with PowerShell

John WilsonJohn Wilson Nov 18, 2026 869 views

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.
Before you start

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.

Solution 1Recommended

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.

1
Install and connect to Graph

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.

2
Retrieve Inbox messages

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".

3
Export duplicate candidates

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.

4
Review and remove copies

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.

Find Duplicate Candidates with Microsoft Graph PowerShell
Check other folders separately: The Inbox query does not cover subfolders or identify messages without an Internet Message ID. Review other affected folders and compare message details before deleting anything.
Free Microsoft Office alternative

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.

Review and sort exported duplicate-candidate CSV reports in WPS SpreadsheetsOpen and edit Microsoft Excel XLSX and XLS filesUse a familiar spreadsheet interface to inspect message detailsWork with a free, lightweight Office suite
microsoft office alternative - wps office

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.