Using Powershell to archive mailboxes before certain date
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
Related videos on Youtube
ItsPronounced
Constantly learning web application development. Self taught ASP.NET and php since 2003.
Updated on September 18, 2022Comments
-
ItsPronounced over 1 year
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).
-
ItsPronounced about 12 yearsWow thanks! This worked perfectly. is there a way to exclude Calendar objects? Looking into it myself right now. THANKS!
-
Mathias R. Jessen about 12 years@drpcken Updated answer...
-
ItsPronounced about 12 yearsI was just about to ask becuase it deleted some of my contacts too :( But thanks!
-
ItsPronounced about 12 yearsWell 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.
-
Mathias R. Jessen about 12 yearsTry 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 :-) -
ItsPronounced about 12 yearsThanks, I will have to restore from archive. Shouldn't be a problem. Thanks!