The retention policy is a very powerful feature of Exchange Online but at the same time, unfamiliar to the most of us.
The Retention policy enables us to manage mail item’s Retention. In other words: Manage email before the email manage you!
The “Retention policy” is a collection of Retention Tags. Each Tag includes setting or “action” that will be applied to Mail item after a specific amount of time (measured in days). The “Action” could be:
- Delete Mail items
- Move Mail item to the Archive
Exchange Online includes built-in default Retention policy (Default MRM Policy) that is applied automatically for each Office 365 Mailboxes.
In this article, we review PowerShell commands that relate to the Retention Policy.
An additional issue is the Folder Assistant; this is the Exchange Online process that runs in the background and enforces or applies the Retention Policy on the Office 365 Mailboxes.
Article Table of content | Click to Expand
PowerShell | Help & additional information
Running PowerShell commands in Office 365 based environment
To be able to run the PowerShell commands specified in the current article, you will need to create a remote PowerShell with Azure Active Directory or Exchange Online. In case that you need help with the process of creating a Remote PowerShell session, you can use the links on the bottom of the Article.
1. Manage Retention Policy | Apply Retention Policy
1.1 – Apply Retention policy for a single Mailbox
PowerShell command syntax
1 | Set-Mailbox <mailbox> –RetentionPolicy <Policy name> |
PowerShell command Example
1 | Set-Mailbox John@o365info.com -RetentionPolicy "My Policy" |
1.2 – Apply Retention Policy to ALL Office 365 Mailbox’s (Bulk Mode)
PowerShell command syntax
1 | $UserMailboxes = Get-Mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $UserMailboxes | Set-Mailbox –RetentionPolicy <Policy name> |
PowerShell command Example
1 | $UserMailboxes = Get-Mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $UserMailboxes | Set-Mailbox –RetentionPolicy "My Policy |
2. Manage Retention Policy | Remove Retention Policy
2.1 – Remove Retention Policy from a single a Mailbox (set to Null)
PowerShell command syntax
1 | Set-Mailbox <Mailbox> -RetentionPolicy $Null |
PowerShell command Example
1 | Set-Mailbox John@o365info.com-RetentionPolicy $Null |
2.2 – Remove Retention Policy for a Mailbox Retention policy to ALL Office 365 Mailbox’s (Bulk Mode)
PowerShell command Example
1 | $UserMailboxes = Get-Mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $UserMailboxes | Set-Mailbox –RetentionPolicy $Null |
3. Manage Retention Policy | Display information about Retention Policy
3.1 – Display the Retention Policy applied to a User Mailbox
PowerShell command syntax
1 | Get-Mailbox <Mailbox> | FL RetentionPolicy |
PowerShell command Example
1 | Get-Mailbox John@o365info.com| FL RetentionPolicy |
3.2 – Display the Retention Policy applied to all Office 365 users Mailbox’s
PowerShell command Example
1 | Get-Mailbox -ResultSize Unlimited | where {$_.name -Notlike '*DiscoverySearchMailbox*'} | select Alias, RetentionPolicy |
4. Retention Policy Tags | Manage Default Retention Policy Tags settings
4.1 – Set the number of days for Deleted items, Tag
PowerShell command syntax
1 | Set-RetentionPolicyTag "Deleted Items" –AgeLimitForRetention <Number of days> |
PowerShell command Example
1 | Set-RetentionPolicyTag "Deleted Items" -AgeLimitForRetention 100 |
4.2 – Disable Deleted items Tag
PowerShell command Example
1 | Set-RetentionPolicyTag "Deleted Items" -RetentionEnabled $False |
4.3 – Set the number of days for Junk Email Tag
PowerShell command syntax
1 | Set-RetentionPolicyTag "Junk Email" -AgeLimitForRetention <Number of days> |
PowerShell command Example
1 | Set-RetentionPolicyTag "Junk Email" -AgeLimitForRetention 100 |
5. Retention Policy Tags | Create NEW Retention Policy Tags
5.1 – Create NEW tag for Sync Issues Folder
PowerShell command syntax
1 | New-RetentionPolicyTag -Name <Tag name> -Type 'SyncIssues' -AgeLimitForRetention <number of days> -RetentionAction 'DeleteAndAllowRecovery' -RetentionEnabled $True |
PowerShell command Example
1 | New-RetentionPolicyTag -Name "My Tag" -Type 'SyncIssues' -AgeLimitForRetention 120 -RetentionAction 'DeleteAndAllowRecovery' -RetentionEnabled $True |
6. Activate Folder Assistant
6.1 – Run the Managed Folder Assistant for a specific Mailbox
PowerShell command syntax
1 | Start-ManagedFolderAssistant <Mailbox> |
PowerShell command Example
1 | Start-ManagedFolderAssistant John@o365info.com |
6.2 – Run the Managed Folder Assistant for all Office 365 Mailbox’s (Bulk Mode)
PowerShell command Example
1 | $UserMailboxes = Get-Mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')} $UserMailboxes | ForEach {Start-ManagedFolderAssistant $_.Identity} |
7. Manage Deleted items policy tag
7.1 – Set Deleted items policy for 30 days for specific user
PowerShell command syntax
1 | Get-Mailbox | Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor <Number of Days> |
PowerShell command Example
1 | Get-Mailbox John | Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor 30 |
7.2 – Set Deleted items policy for 30 days for ALL user (Bulk)
PowerShell command Example
1 | Get-Mailbox -ResultSize Unlimited | Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor 30 |
7.3 – Display information about Deleted items policy for specific user
PowerShell command syntax
1 | Get-Mailbox <Mailbox> | FL Alias,RetainDeletedItemsFor |
PowerShell command Example
1 | Get-Mailbox John |FL alias,RetainDeletedItemsFor |
7.4 – Display information about Deleted items policy for ALL users
PowerShell command Example
1 | Get-Mailbox -ResultSize Unlimited |FL alias,RetainDeletedItemsFor |
Getting started with Office 365 PowerShell
Get more information about the Naming Conventions that are used in the PowerShell articles – Help and additional information – o365info.com PowerShell articles
To get more information about the required remote PowerShell commands that you need to use for connecting to Exchange Online, read the following article:
Connect to Exchange Online by using Remote PowerShell
To get more information about the required software component + the remote PowerShell commands that you need to use for connecting Azure Active Directory, read the following article: Part 2: Connect to Office 365 by using Remote PowerShell
If you are new in the PowerShell world, you can read more information about how to start working with PowerShell in Office 365 based environment in the following article series: Getting started with Office 365 PowerShell – Part 1, Part 2, Part 3.
In case that you need more information about how to use the o365info PowerShell scripts that I add to the PowerShell articles, you can read the article – How to run and use o365info PowerShell menu script
Additional reading- Assign retention policy to email messages
- Apply a retention policy to mailboxes
- Get-RetentionPolicy
- How to apply Retention Policies to all mailboxes
- Set Retention Policies in Office 365 via PowerShell
Now it’s Your Turn!
It is important for us to know your opinion on this article
It is important for us to know your opinion on this article


Great information. Applying a policy is easy but for one thing. You need to know the name of the policy. How can I get a list of available policies? (Once I know their names, finding out what their settings are is also easy!)
https://technet.microsoft.com/en-us/library/dn775046(v=exchg.150).aspx