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

Kay Zin Aye 40 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

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Vasil Michev 123.5K Reputation points MVP Volunteer Moderator
    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.