Powershell – Move emails older than x date to deleted items folder via powershell

exchange-2010powershell

I am trying to move e-mails older than 1 year, or any date for that matter, to the deleted items folder via power shell.

I've tried running :

Get-Mailbox -Identity myuser | Search-Mailbox -SearchQuery "sent:<01/01/2014" however this errors because the mailbox searched cannot be the same as the target mailbox.

How would I go about moving these old e-mails to the deleted items folder?

Best Answer

I don't think you can use the powershell to target an export to the original mailbox. However, you can use the query to export item to an admin account then delete from the source account.

You should be creating a retention policy, and apply them to users if you want to archive them to delete item folder
Create a Retention Policy (https://technet.microsoft.com/en-us/library/ff625224(v=exchg.141).aspx)
Apply a Retention Policy to Mailboxes (https://technet.microsoft.com/en-us/library/dd298052(v=exchg.141).aspx)

If you are interested in exporting them and remove it from the user's mailbox. You can use the following
Get-mailbox -Identity myuser | Search-mailbox -searchQuery received:<1/1/2014 -TargetMailbox "Admin" -TargetFolder "Backup" -DeleteContent