We have a separate archiving appliance that archives messages as they come in using a journal account. Before this I would have to manually archive each mailbox to a PST file and then store the file on our storage server. Luckily I don't have to do that anymore.

My question is, using Powershell, is it possible to go in to each (or all at once) mailbox and remove email messages before a certain date? This would prevent me from still having to archive each mailbox to a PST file, even though I could delete the PST file later. I don't want to touch calendar items, only mail items (folders and subfolders).


If you have Exchange Server 2007 SP1, you can use the Export-Mailbox cmdlet, with the -DeleteContent flag and without a target, to simply delete to email items that otherwise would have been exported:

Get-Mailbox | Export-Mailbox -EndDate (Get-Date).AddDays(-90) -DeleteContent

In the example, all items in all folders, from before 90 days ago, will be deleted. You'll need to have FullAccess rights on each mailbox you perform this operation on.

To exclude certain folders, like Contacts or Calendar, use the -ExcludeFolders flag, like this:

Export-Mailbox -ExcludeFolders "\Contacts","\Calendar" -DeleteContent
  • Wow thanks! This worked perfectly. is there a way to exclude Calendar objects? Looking into it myself right now. THANKS! – drpcken Mar 13 '12 at 16:42
  • @drpcken Updated answer... – Mathias R. Jessen Mar 13 '12 at 17:05
  • I was just about to ask becuase it deleted some of my contacts too :( But thanks! – drpcken Mar 13 '12 at 17:22
  • Well sorry to say but it deleted some contacts and calendar appointments that were very important. Not your fault I should have mentioned it before running the command. Is there anyway I can restore these items from the Exchange Server (without going to my archiver)? I can make a new question if needed. – drpcken Mar 13 '12 at 17:30
  • 1
    Try to log in to OWA, check Deleted Items and then select the items and recover deleted items. If they're not there, you probably have to restore them from the archive. Word of advice, always test something like this on a dummy mailbox :-) – Mathias R. Jessen Mar 13 '12 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.