How to Create a Retention Policy to Preserve Deleted Items in SharePoint Online?

Requirement: Create a retention policy to preserve deleted items in SharePoint Online

How to create a Retention Policy for SharePoint Online?

SharePoint Online retains deleted items for 93 days before they get deleted permanently. What if you want to preserve deleted items for more than 93 days? Say, for 10 years as per your regulatory compliance policies or legal requirements? Well, Office 365 retention policies allow us to retain and recover deleted items and files. You can preserve deleted files with the help of retention policies in the Office 365 compliance center. Basically, You have to create a retention policy and apply it to areas like SharePoint, OneDrive, etc. Here is how to create a retention policy in the Office 365 compliance center:

  • Login to Microsoft Admin center at https://admin.microsoft.com as global administrator >> Open “Compliance Center” https://compliance.microsoft.com link from the left navigation.
  • In the Compliance Center, click on “Policies” from the left navigation >> Choose “Retention” >> Click on “New retention policy”.
  • Provide a name to your policy and optionally the description. E.g. “Retain Deleted items for 10 years”.
    create retention policy
  • We can use these policies to either preserve or remove items, We’ve also options like the retention policy based on the creation date or the last modified date. Here in my case, I’ve selected to retain deleted content for 10 years and not to delete the content automatically.
    retention policy settings
  • Choose locations to preserve such as SharePoint Online and OneDrive for Business. You can apply the policy globally or to specific site collections.
    choose locations for preservation
  • Review your settings and then click on the “Create this Policy” button to create the policy.
  • Wait till the status of the Policy changes from “On (Pending)” to “On (Success) “. Although the compliance center tells us, it may take up to 24 hours to apply the policy, it actually depends on the volume of your content. It took me 10 minutes to activate the policy in my case.
    office 365 compliance policy status

Create a Retention Policy using PowerShell

The above steps can be automated with the Help of Exchange Online Management Shell. The following steps will guide you through the process of creating a Retention Policy using PowerShell for SharePoint Online and OneDrive:

Try {
    #Connect to Compliance Center through Exchange Online Module
    Connect-IPPSSession

    #Create a Retention Policy for SharePoint Online & OneDrive
    $Policy = New-RetentionCompliancePolicy `
        -Name "Retention Policy" `
        -Comment "Retention Policy to Preserve Deleted Items" `
        -SharePointLocation All `
        -OneDriveLocation All `
        -ModernGroupLocation All `
        -Enabled $True

    #Create a Rule for the Policy
    New-RetentionComplianceRule `
        -Name "SharePoint Online Retention Policy Rule" `
        -Policy $Policy.Id `
        -RetentionDuration 365 `
        -RetentionComplianceAction KeepAndDelete `
        -ExpirationDateOption ModificationAgeInDays

   }
Catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}  

SharePoint Online Retention Policy in Action:

Once the retention policy is applied to your SharePoint Online site(s), You’ll see the below changes:

  • You’ll see a new library, “Preservation Hold Library” on the site contents page as soon as you delete any item or edit an existing item for the first time. (This library is visible only to Site collection administrators!). You can recover deleted items from it.
  • If you try to delete a list or library that has content, you’ll see an error message, “List cannot be deleted while on hold or retention policy.”
  • You can’t delete a folder with its contents! If you try, you’ll face the “You have to delete all the items in this folder before you can delete the folder.” error! You can either use Explorer view or PowerShell to delete all files in a folder recursively.
  • You can’t delete a site collection from the Admin center (or even with PowerShell!). You must exclude the site from the retention policy to delete the site.

When a list item or a document is deleted in SharePoint, it goes to the recycle bin, and a copy of the item is sent to the preservation hold library! Also, a copy of the original content is retained in the Preservation Hold library when users edit existing documents (that are created prior to applying the policy!).

Storage Consumption by the SharePoint Retention Policies:
When a retention policy is active, SharePoint keeps copies of deleted or changed documents in the “Preservation Hold Library” and starts consuming the storage quota. So, when users edit and delete a lot of files,  the versions build-up, and you can expect higher storage consumption.

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

2 thoughts on “How to Create a Retention Policy to Preserve Deleted Items in SharePoint Online?

  • Thanks, your article helped to solve my requirement!

    Reply

Leave a Reply

Your email address will not be published.