PowerShell command to delete all the users in emails before certain date

Karim Sedik 1 Reputation point
2021-11-10T23:54:02.253+00:00

Hello,
I am looking for the PowerShell command that cloud be used to delete all the users' emails in a tenant before certain date, in Exchange Online.
Thanks

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

1 answer

Sort by: Most helpful
  1. KyleXu-MSFT 26,396 Reputation points
    2021-11-11T02:56:08.39+00:00

    @Karim Sedik

    I think this is the one that you want: Search for and delete email messages

    If you are not familiar with PowerShell, you could create the search request from GUI:
    148404-qa-kyle-10-48-14.png
    148364-qa-kyle-10-50-49.png

    After searching complete, you could connect to Security & Compliance Center, then use command below to delete those searched emails:

    New-ComplianceSearchAction -SearchName "SearchName" -Purge -PurgeType HardDelete  
    

    148442-qa-kyle-10-55-00.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

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.