I need to delete the Shared Mailbox email in the Inbox folder that is reaching about 420,000+ older than 1-month-old from today date.
Get-Mailbox -Filter '(RecipientTypeDetails -eq "SharedMailbox")' | Search-Mailbox '[email protected]' -TargetMailbox '[email protected]' -TargetFolder 'Inbox' -SearchQuery "kind:Email AND Received:
"18/10/2018..1/1/1970
"" -DeleteContent
The script that I have found does not have the timestamp capability, and I am not sure how to modify it, so I can run this script as the scheduled task every month.
You could refer to the below code:
$DT = (Get-Date).AddDays(-30).ToString("d")
Get-Mailbox | Search-Mailbox -SearchQuery "From:[email protected] AND Subject:'Voicemail Message' AND received:< $DT" -TargetMailbox "helpdesk" -TargetFolder "SearchAndDeleteLog" -logonly -loglevel Full
For more information, please refer to the below link: