Skip to content

Manage Retention Policy and Tags by using PowerShell | Office 365

In the current article, we will review how to use PowerShell commands for managing Retention Policy in Exchange Online environment. The retention policy is a very powerful feature of Exchange Online but, at the same time, unfamiliar to most of us.

Connect to Exchange Online PowerShell

To be able to run the PowerShell commands specified in the current article, you will need to Connect to Exchange Online PowerShell.

Start Windows PowerShell as administrator and run the cmdlet Connect-ExchangeOnline.

Connect-ExchangeOnline

Retention policy

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:

  1. Delete Mail items
  2. 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.

1. Manage Retention Policy | Apply Retention Policy

1.1 – Apply Retention policy for a single Mailbox

PowerShell command syntax:

Set-Mailbox –RetentionPolicy <Policy name>

PowerShell command example:

Set-Mailbox John@o365info.com -RetentionPolicy "My Policy"

1.2 – Apply Retention Policy to ALL Office 365 Mailbox’s (Bulk Mode)

PowerShell command syntax:

$UserMailboxes = Get-Mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
$UserMailboxes | Set-Mailbox –RetentionPolicy <Policy name>

PowerShell command example:

$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:

Set-Mailbox <Mailbox> -RetentionPolicy $Null

PowerShell command example:

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:

$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:

Get-Mailbox <Mailbox> | FL RetentionPolicy

PowerShell command example:

Get-Mailbox John@o365info.com| FL RetentionPolicy

3.2 – Display the Retention Policy applied to all Office 365 users Mailbox’s

PowerShell command example:

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:

Set-RetentionPolicyTag "Deleted Items" –AgeLimitForRetention <Number of days>

PowerShell command example:

Set-RetentionPolicyTag "Deleted Items" -AgeLimitForRetention 100

4.2 – Disable Deleted items Tag

PowerShell command example:

Set-RetentionPolicyTag "Deleted Items" -RetentionEnabled $False

4.3 – Set the number of days for Junk Email Tag

PowerShell command syntax:

Set-RetentionPolicyTag "Junk Email" -AgeLimitForRetention <Number of days>

PowerShell command example:

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:

New-RetentionPolicyTag -Name <Tag name> -Type 'SyncIssues' -AgeLimitForRetention <number of days> -RetentionAction 'DeleteAndAllowRecovery' -RetentionEnabled $True

PowerShell command example:

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:

Start-ManagedFolderAssistant <Mailbox>

PowerShell command example:

Start-ManagedFolderAssistant John@o365info.com

6.2 – Run the Managed Folder Assistant for all Office 365 Mailbox’s (Bulk Mode)

PowerShell command example:

$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:

Get-Mailbox | Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor <Number of Days>

PowerShell command example:

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:

Get-Mailbox -ResultSize Unlimited | Set-Mailbox -SingleItemRecoveryEnabled $True -RetainDeletedItemsFor 30

7.3 – Display information about Deleted items policy for specific user

PowerShell command syntax:

Get-Mailbox <Mailbox> | FL Alias,RetainDeletedItemsFor

PowerShell command example:

Get-Mailbox John | FL alias,RetainDeletedItemsFor

7.4 – Display information about Deleted items policy for ALL users

PowerShell command example:

Get-Mailbox -ResultSize Unlimited | FL alias,RetainDeletedItemsFor
o365info Team

o365info Team

This article was written by our team of experienced IT architects, consultants, and engineers.

This Post Has 2 Comments

  1. 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!)

Leave a Reply

Your email address will not be published. Required fields are marked *