Exchange 2013 Powershell - clean up Deleted Items folder based on date

Hello,

Our company has the unfortunate luck of being around for 10+ years with no real limits on mailbox sizes. I have multiple Deleted Items folders with 15k+ mail pieces in them. My understanding is that if I apply the Retention Policy to those folders now, to let's say wipe items older than 1 year, since this is the first time retention tags would get applied, the first items would get deleted one year from now (unless I am mistaken here), instead of wiping right away any items that were already deleted over a year ago...

My idea was to set those tags, but in the meantime, come up with a PS script that would be run against most offending mailboxes to wipe the excess mail pieces to get us by till the Retention Policies start working their magic.

Has anyone ever attempted running such script? I have seen several ideas on line, but all the forums report mixed results... Is there another tool I could use to selectively/administratively  wipe emails from few folders in other mailboxes, short of doing it from each user's Outlook?
LVL 1
rr2rAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
You can use the below script do to this for either a single user or all users...

Single User
Search-Mailbox -Identity user1-SearchQuery '#deleted items#' -DeleteContent

Open in new window


For All User Mailboxes
$Mailboxes = get-mailbox -resultsize "unlimited"
ForEach ($M in $Mailboxes)
        {
                Search-Mailbox -Identity $m.UserPrincipalName -SearchQuery '#Deleted Items#' -DeleteContent -Confirm:$false

}

Open in new window


Will.
rr2rAuthor Commented:
Is there a way to make it run against emails older than a year let's say?
Will SzymkowskiSenior Solution ArchitectCommented:
You can try the below for this.

Search-Mailbox -Identity user1-SearchQuery '#deleted items# and Received:>("12/31/2014")' -DeleteContent

Open in new window


Will.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

rr2rAuthor Commented:
I tried your suggestions and I got an error back from PS. It was last week so I have no recollection of the error but I will work on this hopefully tomorrow or Wednesday. I secured access to old mailbox that I can test on so hopefully we can figure this out.
rr2rAuthor Commented:
The last example did not seem to do anything, although it did complete the run. Going to do some more testing.

Searching online is seems that the Search-Mailbox cannot be targeted at a specific folder as for example described here: https://social.technet.microsoft.com/Forums/exchange/en-US/a7e9cdab-cb64-42df-b2dd-804d1bbab6ab/searchmailbox-restricted-to-single-subfolder
rr2rAuthor Commented:
I ended up working with the user and created a secondary profile on a different machine to help him with the cleaning. The script above were not specific enough, but I think they would work in different situations.
rr2rAuthor Commented:
Although it did not exactly what I wanted, I am sure someone could find it helpful.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.