Select and Clean Out Exchange 2007 Mailbox using a Custom Attribute

We were getting slim on storage on our Exchange server so I had to knock out some cleanup today. I saw that there were several service accounts with 40K messages or so apiece in them. Not sure how common these mailboxes are, but some are dumping grounds for NDRs, network/service alerts, or in our case, mail flow monitoring accounts. So, I composed this simple command to clean out the inbox of those service accounts. This script is for 2007, not 100% how different the script would be in 2010 since I know they made some significant changes to the 2010 Export-Mailbox command, but this worked like a dream in 2007:

Export-Mailbox -Identity ‘service-mailbox’ –DeleteContent

This quick script will delete all messages from the mailbox with no backup. Of course, you have to replace ‘service-mailbox’ with the alias of your service mailbox.

Now, I took it one step further. In order to repeat this process on a semi-regular basis, I added an ‘svc’ value to Custom Attribute 15. I then wrote this command to select these accounts and clean them out:

Get-mailbox -Filter { CustomAttribute15 -eq ‘svc’} | Export-Mailbox –DeleteContent

I personally ran the above command with a –WhatIf at the end of it to make sure I was going to be cleaning out the mailboxes I had intended to clean out.

I now have a command I can schedule to run monthly to keep these mailboxes under control.

Advertisements