I often use this command in PowerShell as a easy method to clear down one of our huge shared mailboxes where we only need to keep the e-mails for 6 months.
Search-Mailbox -Identity Sales -SearchQuery '(Received:01/01/2000..31/05/2017)' -DeleteContent
What I want to know is how I can modify this so that it calculates greater than or equal to 6 months ago so that I can make it a scheduled task that runs in the background once a day?
i.e. something that if I ran it now it would calculate:
(Received:>=04/05/2017)
I'm not actually sure if the :>=
thing is valid either?
"(Received:01/01/2000..$((Get-Date).AddMonths(-6).ToString(""dd'/'MM'/'yyyy"")))"