How to Delete Files from the Preservation Hold Library?

Requirement: Delete Files from SharePoint Online/OneDrive for Business Preservation Hold Library.

What is preservation hold library in SharePoint Online or OneDrive for Business?

The Preservation hold library in Sharepoint Online or OneDrive is a special type of document library that holds the content to help organizations meet legal and compliance requirements. This library has several key features that distinguish it from other types of libraries, including the ability to place holds on content, to require logs of all user activity, and to enable auditing. The preservation hold library keeps a copy of all modified or deleted files as enforced by the Retention policy or eDiscovery holds. However, there are sometimes you may want to remove files from the preservation hold library, such as Accidental uploads, Migration issues, Copy, etc. In my case, a user uploaded about 500 GB size files for temporary sharing. After it served its purpose, they deleted it. However, the Preservation hold library had a copy of deleted files and occupied the storage quota! So, How do I clear the preservation hold library?

How to access the preservation hold library?

The preservation hold library is accessible to site owners and site collection administrators from the “Site contents” page. URL Shortcut: https://YourDomain.sharepoint.com/sites/YourSite/PreservationHoldLibrary, Similarly for OneDrive for Business sites, it’s at: https://YourDomain-my.sharepoint.com/personal/YourAccount_YourDomain_com/PreservationHoldLibrary

access preservation hold library in sharepoint online

How to delete the preservation hold library in SharePoint Online?

In order to delete files in the preservation hold library, You got to do the following in Microsoft Purview Compliance Portal first, as a global admin:

  1. If you have any Retention Policies – Exclude the site from the retention policy.
  2. If you have eDiscovery cases – Close all eDiscovery cases.
  3. If you have Data loss prevention policies – Disable them.

Otherwise, when you try to delete a file in the Preservation Hold Library, you’ll get an error message:

Sorry, something went wrong. The server has encountered the following error(s): <File Name> This library contains items that have been modified or deleted but must remain available due to eDiscovery holds. Items cannot be modified or removed.

This library contains items that have been modified or deleted but must remain available due to eDiscovery holds. Items cannot be modified or removed.

Once the site is cleared from the above three compliance policies, it takes 30 days to remove the files under the preservation hold library. What if you want to regain the storage space immediately? Well, You can delete files from the preservation hold library, as you do with any other SharePoint document libraries, by selecting them and clicking the delete button.

Delete files from the preservation hold library using PowerShell

Deleting all files from the web browser user interface could be cumbersome if there are plenty of files in the preservation hold library. So, let’s use PowerShell to clear the preservation hold library:

$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
$ListName = "Preservation Hold Library"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Delete all files from the library
Get-PnPList -Identity $ListName | Get-PnPListItem -PageSize 100 -ScriptBlock {
    Param($items) Invoke-PnPQuery } | ForEach-Object { $_.Recycle() | Out-Null
}

This script deletes all files from the preservation hold library of the given site (Don’t forget to empty both stages of the recycle bin, as we are sending all files to recycle bin, instead of permanently deleting them!). Similarly, to delete files from OneDrive for Business site, just change the SiteURL parameter in the above script.

Delete Preservation Hold Library in OneDrive using PowerShell

How about removing the preservation hold library altogether? From the web browser interface, You can’t do that because you won’t find the “Delete this document Library” in this document library! So, the solution is: Use PowerShell to delete the preservation hold library.

#Config Variables
$SiteURL = "https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com"
$LibraryName ="Preservation Hold Library"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive 

#Get the Library
$Library = Get-PnPList -Identity $LibraryName
      
#Check if document Library exist
If($Library -ne $Null)
{
    #Set Allow Deletion Property to True
    $Library.AllowDeletion = $True
    $Library.Update()
    Invoke-PnPQuery

    #powershell to remove document library
    Remove-PnPList -Identity $LibraryName -Force -recycle
    Write-host -f Green "Preservation Hold Library Deleted Successfully!"
}
Else
{
    Write-host -f Yellow "Could not find Preservation Hold Library!"
}

To enable deletion on the library, we have set the “AllowDeletion” property to true and then deleted the library. By default, its value is false, which prevents us from deleting this library.

Closed eDiscovery cases and excluded site from Retention Policy – But still unable to delete the Preservation Hold Library?

Wait for an hour if you have made any changes in the Purview compliance center. This could also be due to invalid/orphan policies. Run the Office 365 diagnostic from this link: https://aka.ms/PillarInvalidRetention and follow the wizard to clear them. Good luck!

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 Delete Files from the Preservation Hold Library?

Leave a Reply

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