tech-man Posted December 10, 2019 Posted December 10, 2019 Hello Does anyone have a Powershell script to delete all message from a users mailbox and folders before a specified date? Thanks
djm968 Posted December 10, 2019 Posted December 10, 2019 Search-Mailbox -identity -SearchQuery 'Received<="2012-12-31" AND kind:email' -DeleteContent
tech-man Posted December 10, 2019 Author Posted December 10, 2019 Thanks for that.... Will this include sent email's as well?
djm968 Posted December 10, 2019 Posted December 10, 2019 (edited) You will need to change the SearchQuery as below. Be aware, -DeleteContent is a pretty disruptive command and it may be best to test the code by modifying it to log the output first. Search-Mailbox -identity -SearchQuery 'Sent<="2012-12-31" AND kind:email' -DeleteContent This code searches the mailbox for messages that cmatch the query and logs the result in the SearchAndDeleteLog folder in the administrator's mailbox. Messages aren't copied to the target mailbox. Search-Mailbox -Identity "mailboxname" -SearchQuery 'Sent<="2012-12-31" AND kind:email' -TargetMailbox "administrator" -TargetFolder "SearchAndDeleteLog" -LogOnly -LogLevel Full Edited December 10, 2019 by djm968 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now