PowerShell command to delete items in specific mailbox folder in M365 Exchange Online

Kay Zin Aye 20 Reputation points
2025-02-26T03:29:59.1+00:00

Hello,

I 've an issue due to so many email items (over 700,000 items) in outbox and couldn't see in outlook desktop app and OWA. Although tried to delete with retention policy, those items are not reducing for over a month. Therefore, I would like to get PowerShell command to delete those items ( with date / time range) if possible. Screen Shot is added below for your reference.outbox- cos

Best Regards,

Kay Zin

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,766 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 114.5K Reputation points MVP
    2025-02-26T07:22:09.94+00:00

    Retention policies should be the best solution here, have you done some troubleshooting on that part?

    PowerShell on its own won't help you, as Microsoft removed the Search-Mailbox cmdlet a while back. The "alternative" is inadequate for such scenarios, and won't get you anywhere, but for the sake of completeness, here it is: https://learn.microsoft.com/en-us/purview/ediscovery-search-for-and-delete-email-messages

    On the positive side, New-ComplianceSearch/Action does allow you to target specific folders. And you can indeed script a loop that deletes items at batches of 10... it's just slow and annoying. Here's a sample script just in case: https://practical365.com/compliance-search-purge/

    Instead, I would suggest you use an EWS-based or Graph API based script. This one is a good starting point: https://github.com/David-Barrett-MS/PowerShell-EWS-Scripts/wiki/Merge-MailboxFolders.ps1


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.