Just about every company has a few unmonitored mailboxes that are used to provide functionality to an application or other services like a helpdesk ticketing system. Often these mailboxes receive mail but the mail never gets deleted and the mailbox grows in size. In this post, we will take a look at how to use the Recovery Manager for Exchange PowerShell cmdlets to deal with this issue.
Recovery Manager for Exchange allows you to search PST files, live mailboxes, Exchange databases, etc. at the same time via a single interface. Once you have found the items you are looking for you can restore them to the original location, another mailbox or a PST. This is the primary use for Recovery Manager for Exchange. However, to address our scenario above we will need to accomplish the following using PowerShell:
The complete command is as follows: Get-RMEExchangeServer -TargetDomain "dell.local" | Get-RMEMailbox -MailboxNameInclude "ITDepartment" | Get-RMEMessage -TimeMatch received -TimeBefore 02/15/2014 | Delete-RMEMessage –SkipErrors
Let’s break this down a little.
Get-RMEExchangeServer retrieves all Exchange Servers along with the mailboxes they host from a particular Exchange organization. You can use –TargetDomain or –ServerName to retrieve a list of Exchange Server objects that are part of the organization. In my example my domain is called dell.local.
Get-RMEMailbox retrieves mailboxes that match particular criteria. There are numerous options for this command and it is probably a good idea to run Get-Help Get-RMEMailbox for more info. Some example for filtering out your target mailboxes would be mailboxes of a certain size, ones that have received messages from a particular user, message count greater or less than some value and many more. We are connecting to a specific mailbox using –MailboxNameInclude. In our example we are looking for the ‘ITDepartment’ mailbox.
Get-RMEMessage is similar to the above command but searches for messages that match the criteria we specify. Once again there are numerous options that we can specify to filter out exactly what we need. In our example we are getting anything from before a specific date using the –TimeBefore option.
As you will see in the final script below we can use Microsoft’s utility command Get-Date to get the current date and time and then subtract 90 days by adding a negative number. Ahhh, this is why we learned to add negative numbers in school!
$mydate = (Get-Date).AddDays(-90)
Delete-RMEMessage is pretty self-explanatory. It deletes the messages that we specified in the above command. We also told it to ignore errors.
Now let us put this thing into a script
Here is the completed script that we can use to accomplish our task. Note that we are deleting messages older than 90 day from the time the script is run.
+++++++++++++++++ Delete Email Older Than 90 Days +++++++++++++++++
Get-RMEExchangeServer -TargetDomain "dell.local" | Get-RMEMailbox -MailboxNameInclude "ITDepartment" | Get-RMEMessage -TimeMatch received -TimeBefore $mydate | Delete-RMEMessage –SkipErrors
Note: If you launch the Recovery Manager for Exchange Management Shell from within Recovery Manager for Exchange program group all should work as advertised. However, if you launch PowerShell from any other location you may need to load the Management Shell snap-in using the following command.
This is just the tip of the iceberg. With the set of PowerShell cmdlets provided with Recovery Manager for Exchange there are thousands of different scenarios that can be addressed with a little creativity and of course, a problem to solve.
For more info on Recovery Manager for Exchange and to download a trial copy of the software check out the product page here: