MSExchangeGuru.com

Learn Exchange the Guru way !!!

 

Delete emails using retention policy in Exchange server

Let’s look at how to create a retention policy to delete emails that are more than 365 days for all the users.

Please note that this is NOT a standard request and take caution before proceeding.

My customer had a unique requirement of knowing the amount of emails that would be deleted in each inbox when/if the policy is applied

We used the script in the TechNet and I would like to share how I achieved using that script

The script can be downloaded from TechNet Script. All credit goes to the author – “Rick_2CA”

This script has few customizable portions where we can customize it to our requirements.

For this Blog I am going to show how to find the details on one database

Below are the customizable portion that is present in the script

########################################################################################


# Set the Mailbox variable to the query you wish to search

# Enable ONE of the following $Mailbox options. They are ordered in such a way that if two

# options are enabled the last one set will be a smaller set of users than the previous.

    ## Search all mailboxes in all databases

        # $Mailbox = Get-MailboxDatabase | Get-Mailbox

    ## Search all mailboxes on a server (EDIT THE SERVER NAME)

        # $Mailbox = Get-MailboxDatabase -Server SERVERNAME | Get-Mailbox -ResultSize Unlimited

    ## Search a single database (EDIT THE DATABASE NAME)

        # $Mailbox = Get-MailboxDatabase -Identity DATABASENAME | Get-Mailbox -ResultSize Unlimited

    ## Search all users within an organization unit (EDIT THE OU CN)

        # $Mailbox = Get-Mailbox -OrganizationalUnit ou=OUNAME,dc=DOMAINNAME,dc=DOMAINSUFFIX -ResultSize Unlimited

###### The options below allow for a user generated list. If the value you search on results in multiple entries

    ## the script will log an error in the output. The following attributes may be used:

    ## GUID, Distinguished Name (DN), DomainAccount, User Principal Name (UPN), LegacyExchangeDN, SmtpAddress, Alias

    ## Provide a text file with a list of users. One user per line. $Mailbox will be setup later in the script.

        # Enable and configure the two lines below. Include a path ending in “” and a filename.

        # $TXTPath = $env:userprofile + “” + “Desktop” + “”

        # $TXTName = “InputList.txt”

    ## Search mailboxes with a filter

        # $Mailbox = Get-Mailbox -Identity Smith* -ResultSize Unlimited

    ## Search mailboxes out of an array

        # $Mailbox = @(“Smith, John”,”ReceptionDeskUser”)

    ## Search a single mailbox.

         $Mailbox = “user1”

# Set the minimum mail age that should be collected. Note: Leap years are not automatically calculated.

$MailOlderThanDays = 365

########################################################################################

As told before I am going to do it for one of the database so I have to remove the comment (#) in the below line and put my database name, post modification it would look like this.

$Mailbox = Get-MailboxDatabase -Identity Targetdatabase | Get-Mailbox -ResultSize Unlimited

Now specify the number of days’ worth email I am looking for in the below line, also this line have to uncommented

Set the minimum mail age that should be collected. Note: Leap years are not automatically calculated.

$MailOlderThanDays = 365

Now we are all set to run the command.

Note: when we run the script again a database, in large environment it would time to give you the result.

This script does a search-mailbox with the statistics of the mailboxes using the search query as the date.


With this information, we will get to know the approximate amount emails that will get deleted when we apply the retention policy.

With this info in highlight, you may now proceed with applying the retention policy.

Ratish Nair

Microsoft MVP | Exchange Server

Team @MSExchangeGuru

Leave a Reply

Categories

Archives

MSExchangeGuru.com