I have recently been archiving user mailboxes and then using search-mailbox to delete emails before a certain date, dependant on guidance from the user.
The commands I have been using are
$date = (get-date).AddDays(-xxx).Date.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
-xxx sets a date variable that is inline with how far back the user would like to keep their email.
search-mailbox -Identity <alias> -TargetMailbox <alias> -TargetFolder SearchandDelete -SearchQuery {(Receieved -lt $date)} -LogOnly -LogLevel full
This line will do a logonly and send a report to my mailbox with the results. Usually this returns more than 10,000 results so the following like is ran a few times to purge everything before the variable date.
search-mailbox -Identity <alias> -SearchQuery {(Receieved -lt $date)} -DeleteContent
However, using this method also seems to delete some current emails! Let's say the user wishes to keep the last 365 days of email. It is still actually removing emails from the users inbox that may only date back a few days.
Is this a known issue? Are there any workarounds or should I alter my powershell commandlets in any way?
- Edited by cplg Monday, April 20, 2015 1:56 PM edited for clarity