MSExchangeGuru.com

Learn Exchange the Guru way !!!

 

Delete an email message from a list of mailboxes

Please have this script handy coz you wont have time to sit n search for this in the event of a requirment

Target – Delete one specific email from a list of user mailboxes

1. If the email was sent to a distribution group, use this cmdlet to get the list of users in that distribution group

Get-DistributionGroupMember

2. Create a folder on the server

3. Paste all those display name’s to a TXT file, name is as “List.txt” and in that folder

4. Open Shell (with proper permissions) and navigate to the location of the txt file

5. Type: $AdminSessionADSettings.ViewEntireForest = $true to open a session for the whole forest

6. Run the cmdlet:

Get-Content List.txt |Get-Mailbox -Resultsize Unlimited | Export-Mailbox -TargetMailbox Ratish -TargetFolder RecoverEmails -SenderKeywords “name@domain.com” -SubjectKeywords ”Blah Blah Blah” –DeleteContent -StartDate “05/05/11″ –EndDate “05/06/11″ -ExcludeFolders “\Calendar”, “\Contacts” -confirm:$false –MaxThreads 15 -BadItemLimit 10000 |ft Displayname, StandardMessagesDeleted, AssociatedMessagesDeleted

You will get an output like:

DisplayName                   StandardMessagesDeleted          AssociatedMessagesDeleted

———–                                ———————–                                   ————————-

John, Stanton                                                 2                                            0

Reymo, Mike                                                  0                                            0

Thomas, Samuel                                            4                                            2

Ratish Nair
MVP Exchange
Team@ MSExchangeGuru

5 Responses to “Delete an email message from a list of mailboxes”

  1. CypherBit Says:

    This will definitely come in handy.

    Could you please explain the command a bit more, I’m mostly curious as to why it needs to be exported first, can’t we just delete it: “Export-Mailbox -TargetMailbox Ratish” to a folder that probably needs to be created in advance: “RecoverEmails”?

    Also what if I don’t have the SubjectKeywords or SenderKeywords, will it work without one of the two?

  2. yuryk Says:

    Thanks for the info!
    BTW, since of Exch2010 SP1 there is no more Export-Mailbox command, and it was replaced by the Search-Mailbox command (for deleting or searching mails) and the New-MailboxExportRequest (to be able to export a mailbox).

  3. Ratish Sekhar Says:

    @CypherBit – This behavior is by design.
    @yuryk – Your’e right. This is the cmdlet:

    Search-Mailbox -Identity “Ratish Nair” -SearchQuery ‘Subject:”Email to delete”‘ -DeleteContent

  4. Sanjay Says:

    Hi Ratish,

    This script is impressive but I feel its still very time consuming for the distribution list ( It will take more than 5 hours for 400 users), Can’t we drill down more and finish this task within 30 minute max?

  5. LEN Says:

    This is exactly what I am looking for but does not work on Exchange 2010 SP1 Rollup 8. Search-Mailbox is the correct function but I cannot set search dates nor search by sender. Are these flags still available?

Leave a Reply

Categories

Archives

MSExchangeGuru.com