One of my friends want to alter automatic deletion of Junk Email folder so, that it contains only 30 days of messages. The way how it should be done is simple. We can create new retention policy or add Retention policy tag to existing one.
Exchange 2013 (as well as Exchange 2010) contains a set of Retention policy tags grouped in Default Retention and Archive policy. Retention policy tag says, what action will be done with item (for example all Messages calls) within specified Retention period and defined folder. Retention policy can be assigned to mailbox in 1:1 ratio, meaning only one Retention policy can exist on mailbox. It is not supported to have no retention policy on mailbox or to have Retention policy without any Retention policy tag, which might cause, that no item in mailbox will expire. More info about Retention policies and tags can be found here: http://technet.microsoft.com/en-us/library/dd362328(v=exchg.150).aspx Retention Tags and Retention policies are described here:http://technet.microsoft.com/en-us/library/dd297955(v=exchg.150).aspx
Retention policy can contain several types of Retention policy tags:
- One or more retention policy tags (RPTs) for supported default folders
- One default policy tag (DPT) with the Move to Archive action
- One DPT with the Delete and Allow Recovery or the Permanently Delete action
- One DPT for voice mail
- Any number of personal tags
Retention policy is then added to mailbox and it is up to administrator to configure how often Managed Folder Assistant will process mailboxes. I picked up and option to add Retention policy tag to existing policy and here is the result:
Creation of Retention policy tag
To create Retention policy tag we must be sure what action to perform and to what folder type. In my case to delete and allow recovery on all items older than 1 month in folder type Junk Email. Here is the command:
New-RetentionPolicyTag -Name "Junkmail Cleanup" -MessageClass * -AgeLimitForRetention 30.00 :00:00 -RetentionAction DeleteAndAllowRecovery -Type JunkEMail
Assigning Retention policy tag to Retention policy
To add Retention Policy tag to Retention policy use the following commands:
$TagList = (Get-RetentionPolicy "Default Archive and Retention Policy").RetentionPolicyTagLinks $TagList.Add((Get-RetentionPolicyTag 'Junkmail Cleanup').DistinguishedName) Set-RetentionPolicy "Default Archive and Retention Policy" -RetentionPolicyTagLinks $TagList
Assigning Retention policy to mailbox
First gather what retention policy is used and if different, add needed retention policy to mailbox:
Get-Mailbox zbynek | select *ret* Set-Mailbox zbynek -RetentionPolicy "Default Archive and Retention Policy"
Force running Retention policy
Start-ManagedFolderAssistant -Identity zbynek
Change Retention policy cycle
The default is to run policy for all mailboxes daily, but it can be changed altering mailbox server property ManagedFolderWorkCycle. In my example there will be 10 days cycle to run Retention policies on all mailboxes on the server.
Set-MailboxServer EX13NODE2 -ManagedFolderWorkCycle 10