Tech Tip: Set retention period for “permanently” deleted items in Office 365 Exchange accounts using PowerShell cmdlets

By default, Office 365 Exchange accounts are setup to hold deleted items in the Recoverable Items folder for fourteen (14) days. This allows a user or administrator to restore recently deleted items that have been removed from the Deleted Items folder but not yet purged from the Recoverable Items folder using the Recover Deleted Items feature in the Office 365 Outlook Web App (OWA) or Outlook 2016 for Windows.

The retention policy may be changed from a default retention period of fourteen (14) days to a maximum of thirty (30) days using Office 365 PowerShell cmdlets.

The following steps assume that you: (1) are an authorized administrator for your Office 365 tenant, (2) have PowerShell properly setup and running on your computer and (3) are comfortable running PowerShell cmdlets to access/make changes to your Office 365 tenant.

First, you will need to initiate an Office 365 PowerShell session. To initiate an Office 365 PowerShell session:

  • Run Windows PowerShell or Windows Azure Active Directory Module for Windows PowerShell as an Administrator
  • Type the following command at the prompt:

 $UserCredential = Get-Credential

  • Enter your Office 365 Administrator user credentials in the dialog window when prompted
  • Type the following command at the prompt:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

  • Type the following command at the prompt:

Import-PSSession $session

  • Test the session by typing the following command at the prompt:

Get-mailbox

If the last command returns a list of the Office 365 Exchange accounts in your Office 365 tenant, you have properly initiated an Office 365 PowerShell session.

Before making any changes to the retention policy for your Office 365 tenant, you’ll want to check to see how long permanently deleted items are kept in the Recoverable Items folder of your Office 365 Exchange accounts.

The default retention period will be fourteen (14) days; however, if you have more than one Administrator managing your Office 365 tenant and are unaware of any previous changes made to your Office 365 tenant, you’ll want to verify the current settings by following the steps below:

To check the retention policy for a specific mailbox, type the following command at the prompt:

Note: Replace <Name> with mailbox name

Get-Mailbox “<Name>” | FL RetainDeletedItemsFor

To check the retention policy for all mailboxes, type the following command at the prompt:

Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq ‘UserMailbox’)} | FL Name,RetainDeletedItemsFor

To change the retention policy for how long permanently deleted items are kept in the Recoverable Items folder of your Office 365 Exchange accounts, follow the steps below.

Note: The maximum retention period is thirty (30) days. The steps below will set the retention period to the maximum period allowed.

To change the retention policy for a specific mailbox, type the following command at the prompt:

Note: Replace <Name> with mailbox name

Set-Mailbox -Identity “<Name>” -RetainDeletedItemsFor 30 

To change the retention policy for all mailboxes, type the following command at the prompt:

Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq ‘UserMailbox’)} | Set-Mailbox -RetainDeletedItemsFor 30

After making the change to the retention policy, repeat the steps for checking the retention policy for your Office 365 Exchange accounts to verify the changes have been applied accordingly.

Once you are satisfied with the changes, you can end your Office 365 PowerShell session by following the steps below:

To end the Office 365 PowerShell session, type the following command at the prompt:

Remove-PSSession $session

Then, type “Exit” to end and close PowerShell.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s