clean dumpster with specicif date ranges - SearchDumpsterOnly

hello,

can anyone help with this request?


I need to clean a dumpster from 1-1-2010 until now ( keeping everything BEFORE 1-1-2010 )

i am using the cmdlet:

Search-Mailbox identity alias SearchDumpsterOnly DeleteContent

not sure what to add to meet my date range needs.

Thanks

February 9th, 2015 3:20pm

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.

Free Windows Admin Tool Kit Click here and download it now
February 9th, 2015 3:48pm

Hi Thanks for the response.

The above script seems to delete EVERYTHING prior to today's date

< $a=(Get-Date).AddDays(-1).ToString('MM-dd-yyyy') >

My question is how do i specify a date range of 1-1-2010 to < $a=(Get-Date).AddDays(-1).ToString('MM-dd-yyyy') >

leaving everything BEFORE 1-1-2010 untouched

Thanks

February 9th, 2015 4:12pm

Hi ,

Search-Mailbox -identity "nithya@abc.com" -SearchQuery Received>=$('1-1-2010') -DeleteContent -SearchDumpsterOnly

Above is the command which will delete only the emails from the dumpster available on the nithya's mailbox which starts from the date 1-1-2010 and so on.

Please reply me if you have any queries.

Free Windows Admin Tool Kit Click here and download it now
February 10th, 2015 1:21am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics