Powershell – Exchange 2010 Search-Mailbox to delete Exchange Journal emails

exchange-2010powershell

I am using this PowerShell command to try and delete emails from our Exchange Journal,

[PS] C:\Windows\system32>Search-Mailbox -Identity exchangejournal -SearchQuery "Received:12/31/2012..06/30/2013" -DeleteContent

It says it is successful, but it shows ResultItemsCount: 0 and ResultItemsSize: 0 B <0 bytes>. But if I log into that mailbox there are emails from that date. Any suggestions as to what I may be doing wrong?

Thanks

Best Answer

There are several possible caveats here.

Enclose the Keyword Query in curly brackets:

Search-Mailbox -Identity exchangejournal -SearchQuery {received:12/31/2012..06/30/2013}

Make sure your dates matches the ShortDate format on your computer. For example on my machine with Danish locale setting it would be: {received:31-12-2012..30-06-20}. An easy experiment to determine yours would be:

(Get-Date).ToShortDateString()

I've seen problems querying the Received property in the past. If none of the above helps, you might want to try with the Sent property instead:

Search-Mailbox -Identity exchangejournal -SearchQuery {sent:12/31/2012..06/30/2013}

If you get any syntax errors regarding the dates after removing the quotations marks, enclose the date range in parentheses: {sent:(12/31/2012..06/30/2013)}