Hi ,
Please check the below mentioned script.
del C:\Scripts\nithya\dontdelete\*.*
$a=(Get-Date).AddDays(-1).ToString('MM-dd-yyyy')
Search-Mailbox -Identity "nithya@abc.com" -SearchDumpsterOnly -SearchQuery "Received<$a"
-DeleteContent -force >> "C:\Scripts\nithya\dontdelete\Log $(get-date -f dd-MM-yyyy).csv"
Send-MailMessage -To "ramya@abc.com" -From "nithyamail@abc.com" -Subject "nithya Mails Delete Log $(get-date -f dd-MM-yyyy)" -Smtpserver "192.168.1.10" -Attachments "C:\Scripts\nithya\dontdelete\Log $(get-date -f
dd-MM-yyyy).csv"
Above mentioned script will delete the only the emails which belongs to day before yesterday from the dumpster by referring the current date which was called on the script.You should have to adjust the days based on your requirement.
Note : Please test this script for anyone of the test mailbox and then try to use it for production.