Learn Exchange the Guru way !!!


Delete emails from mailboxes – Exchange 2007

The following outlines the steps to delete emails from a set of mailboxes in Exchange 2007.

Issue – Room mailboxes are growing enormous and there is none monitoring those mailboxes to delete emails from it.

Request – Delete all Deleted items and Sent items which are older than 6months from all Room mailboxes in the company.

Well, testing is the key here. You don’t want to listen to what I say and run the script on 1000 mailboxes.

So, we will take one mailbox at a time.

This cmdlet will delete all Sent items and deleted items older than the mentioned date from the mailbox RoomMailbox1

Export-Mailbox -Identity “RoomMailbox1” -IncludeFolders “\Sent Items”, “\Deleted Items” -StartDate “3/22/2005” -EndDate “10/15/2011” –DeleteContent

Now, if we need to perform this on a set of mailboxes, paste all display name’s to a TXT file, name is as “Room.txt”

Navigate to that folder in powershell and run:

Get-Content Room.txt | Export-Mailbox -IncludeFolders “\Sent Items”, “\Deleted Items” -StartDate “3/22/2005” -EndDate “06/15/2011” –DeleteContent –Maxthreads 4

Please specify the switch -PSTFilePath

For Exchange 2010:

Get-mailbox -server MBXServerName -resultsize unlimited | Search-Mailbox -SearchQuery “Received:> $(’06/18/2014′) and and Subject:Your Lottery Results” -TargetMailbox eDiscovery -TargetFolder “Spam_june2014” -LogLevel Full -DeleteContent -force

Get-mailbox -server MBXServerName -resultsize unlimited | Search-Mailbox -SearchQuery “Received:> $(’06/18/2014′) and” -TargetMailbox eDiscovery -TargetFolder “Spam_june2014” -LogLevel Full -DeleteContent -force

Again, we can perform this using MRM but I prefer it this way.

Ratish Nair
MVP Exchange
Team@ MSExchangeGuru

Delete emails from mailboxes, delete Sent items, delete deleted items exchange 2007.

14 Responses to “Delete emails from mailboxes – Exchange 2007”

  1. Phillip Says:

    Greetings Great Ones;
    I am trying to understand how to remove an email that was sent to several hundred users in my organization using the management shell in Exchange 2010.
    I cannot seem to figure out how to specify the time sent, in order to prevent removing unintended emails and specify a single instance of a thread that was mis-communicated.
    I was very well versed at specifying multiple parameters in the EXMerge Utility (Exchange 2003), and have gained some skills with powershell, but today I realized that I am not very competent in what some consider a core skill.

    The more I try to fine tune my query the worse it gets.


  2. john bennett Says:

    That is the tech net for the Export-mailbox command let, take a peek at example 2. That may help some.

    PowerShell tips I use. Make the file in a notepad, save the file as my.script.ps1 for example, then run the file in powershell it self , this way one can edit, try, edit, etc. Reminder; a line that starts with #fun is a comment, so as the script is being edited I often will copy paste the whole line, comment the orginal line. Etc.

    ? Any message outputs from the PS that you did try ?
    2 cents, JB

  3. john bennett Says:

    Part2, I did find this here on the site too. Handy! Phillp this may be more to the point for you. 2 cents JB

  4. Bo Davis Says:


    I have a user that has hundreds of subfolders under the inbox that are missing emails stored within each subfolder(this is the second time this has happened). These messages need to be recovered. The first time this happened I used the recover deleted items going to each subfolder and recovering the missing messages (this took 8 hours). All the missing items were apparently deleted on one day at 4:29PM. I would like to use the recovery tool and recover all deleted items on that specific day for all subfolders below the inbox. Is there a way to do that?



  5. Ulices Diaz Says:

    I tried this and received an error message:

    StatusCode : -1056749164
    StatusMessage : Error occurred in the step: Moving messages.
    Failed to copy messages to the destination
    mailbox store with error:
    MAPI or an unspecified service provider.
    ID no: 00000000-0000-00000000
    ReportFile : C:\Program Files\Microsoft\Exchange Server\L

    Any thoughts? Thanks!

  6. Terry Lauv Says:

    It is useful for me.
    Thank you.

  7. Daniel Says:

    I am trying to find emails that were deleted from one of my mail boxes via Outlook 2003. I am running Exchange 2007. Is there any way I can undelete the emails that were deleted over a month ago? I already tried the Tools > Recover Deleted Items. The emails were not in there. any help please let me know

  8. John Says:


    The command you have specified does not work because you left out a parameter. A target for the export needs to be specified otherwise the command fails.

  9. Prabhat Nigam Says:

    You can only restore the backup unless you have configured item retention over a month.

  10. J Gray Says:

    Excellent information. Very helpful!

  11. Sofiane Says:


    Sorry for my bad english, I’m french. I make a script to delete an email in a specific inbox. It works fine.
    In my script, I used many parameters (Subject, Date, From) to delete the good emails but in the case where the email is a part of a conversation , all the conversation of the say will be deleted… It’s not a good thing.
    I search a solution to can delete only the good mail. I don’t find how to specify the hour or the mail id !
    Someone can help me ?
    Thank you,

  12. Prabhat Nigam Says:

    If you are still looking for a solution then let me know.

  13. Sofiane Says:

    Hello Prabhat,

    Thank you for your reply.
    I have find a solution to do that, it’s ok thank you.

  14. Nasilele Says:

    Thanks, worked like magic. 😉

Leave a Reply




Do NOT follow this link or you will be banned from the site!