Please can someone explain why this power shell code deleted all inbox items!!!!
The code should get today's data and subtract 6 months, this should leave the last 6 months of data in the users mailbox.
What happened was when we ran the code is removed all mailbox items and ignored the date range, even worse because this is a system command this bypasses the recover deleted items causing data loss.
Interested to hear peoples comments.
$from = (Get-date).addyears(-2).ToString("MM/dd/yyyy HH:mm")
$to = (Get-date).addmonths(-6).ToString("MM/dd/yyyy HH:mm")
Get-Mailbox userABC | Search-Mailbox -SearchQuery {"Received:`"$from`"..`"$to`""} -TargetMailbox "administrator" -TargetFolder "SearchAndDeleteLog" -DeleteContent