Exchange Server 2010 - Delete mail from all mailboxes from a specific user.

Ben Cary 1 Reputation point
2021-02-05T10:27:28.403+00:00

Morning,

We have a user, Auto Email, that sends out various reports to many users. Some of which people reply to that triggers a function in the database. The problem is there are now thousands of these emails that need purging, I need to :-

I need to delete all email sent from this account from all user mailboxes prior to 01/01/2021.

I need to delete all email sent to this account from all user mailboxes prior to 01/01/2021.

Is there a way this can be done in Powershell ?

Any help greatly appriciated

B

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,503 questions
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Xzsssss 8,861 Reputation points Microsoft Vendor
    2021-02-08T06:05:33.763+00:00

    Hi @Ben Cary ,

    As Troy said, you could use Search-Mailbox to find these mails and use -DeleteContent to delete them:
    Delete received messages:

    Search-Mailbox -Identity User01 -SearchQuery ‘Received<01/01/2021’ -DeleteContent.  
    

    65231-image.png

    Delete Sent messages:

    Search-Mailbox -Identity User01 -SearchQuery ‘Sent<01/01/2021’ -DeleteContent  
    

    Note these cmdlets will permanently delete these messages, they won’t go to the recovery items folder.

    Regards,
    Lou


    If the response is helpful, please click "Accept Answer" and upvote it.
    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.


  2. Ben Cary 1 Reputation point
    2021-02-11T10:04:00.627+00:00

    Goord morning,

    I get this far :-

    66951-image.png

    I cant see what this error means ?

    Also this look like its going to delete from the mailbox "Autoemail", I wanted to delete from all company mailboxes anything received from the account "AutoEmail" ?

    Sorry for my dumbness


  3. Ben Cary 1 Reputation point
    2021-02-11T14:24:23.287+00:00

    Thanks @Andy David - MVP

    Thanks for the reply.

    I have tried running the first one (i have created a new mailbox called tesetdelete) and put that where you have said target mailbox ?? It then asks for Folder ?

    66937-image.png


  4. Ben Cary 1 Reputation point
    2021-02-11T14:57:59.02+00:00

    Thanks @Andy David - MVP ,

    I tried and failed, maybe I should give up !

    67023-image.png

    0 comments No comments

  5. Andy David - MVP 145.6K Reputation points MVP
    2021-02-11T16:08:56.127+00:00

    Ok, try this then :) ( I dont have a 2010 server to test against). You may have to mess with it a bit and try diff things out

    Get-mailbox -result unlimited | Search-mailbox  -searchQuery {((Received -lt '01/21/2021') -and (from: Autoemail))} -TargetMailbox targetmailbox  -TargetFolder Inbox - 
    LogOnly
    
    0 comments No comments