I've been using Microsoft Exchange Server 2010 SP2. I want to delete user's mails within specific date range. How can I do that? BTW, When to running below command then I've got the following the error.
Search-Mailbox -Identity xxxxx -SearchQuery "Received:> $('01/01/2009') and Received:< $('12/31/2009')" -DeleteContent
Here is my error message :
A search keyword should not be preceeded with comparison modifiers eg. '<', '>', '='.
+ CategoryInfo : InvalidArgument: (:) [], ParserException
+ FullyQualifiedErrorId : 61B67608
UPDATE :
As you mentioned,I've done literally your comments. But ,
Even though about 6000 emails within user's mailbox,it's returned 18 emails below command.
Search-Mailbox -Identity xxxxxxx -SearchQuery {((Received -lt '01 Oct 2009') -and (Received -gt '01 Aug 2013'))} -TargetMailbox targetmailbox -TargetFolder testxx -LogOnly
Best Answer
The reason for you error is because special characters are not escaped. The easiest way is to use double quotes around the value instead of single quotes. Also if you'd like to use a date range then you can use the '..' operator. http://msdn.microsoft.com/en-us/library/office/ee558911(v=office.15).aspx#kql_property_restriction_queries
So
Search-Mailbox xxxxx -SearchQuery "Received:(1/1/2009..12/31/2009)"
This will search for all mail received between 1/1/2009 12:00 am and 12/31/2009 12:00 am.