SharePoint Online: How to Recover Deleted Files from Preservation Hold Library?

Requirement: Restore deleted files from the Preservation Hold library.

SharePoint Online: How to Recover Deleted Items from Preservation Hold Library?

The Preservation Hold Library in SharePoint Online and OneDrive preserves edited or deleted files to ensure there is no loss of data through accidental or willful deletion or editing of items under a Preservation Hold through retention policy, In-place hold, or eDiscovery. Sometimes, when items are deleted even from the recycle bin, you can recover those deleted files from the preservation hold library.

To restore deleted files in SharePoint Online sites from the preservation hold library, do the following:

  1. Login to the site collection where you want to restore files from the “Preservation hold library” as a site collection administrator (Important: preservation hold library is visible only to site collection administrators).
  2. Click on Settings gear >> Site contents.
  3. On the Site contents page, click on “Preservation Hold Library.” This library will be created after the first time the content has been modified or deleted. (Direct URL: https://<your-domain>.sharepoint.com/sites/<your-site>/PreservationHoldLibrary/Forms/AllItems.aspx) restore files from preservation hold library
  4. This library contains all edited and deleted items. Select the deleted file based on the file name and time-stamp values. Click on the “Copy to” button in the ribbon to copy the selected file to the desired library.
    recover items from preservation hold library

Note that the Preservation Hold library is only accessible to site collection administrators.

Items in the preservation hold library are automatically sent to the second-stage recycle bin after the retention period (Based on your retention policy settings – In my setup, it’s 10 years!). Here is another post on creating a retention policy for SharePoint Online sites: How to Create a Retention Policy to Preserve Deleted Items in SharePoint Online?

PowerShell to Restore Files from Preservation Hold Library

Let’s automate recovering files from the preservation hold library to their original location.

# Define Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/ops"
$ListName= "Preservation Hold Library"
$User = "*salaudeen@crescent.com*"

# Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin

# Get deleted Items that match conditions
$DeletedItems = Get-PnPListItem -List $ListName -PageSize 2000  | Where {$_.FieldValues.Modified_x0020_By -like $User} | Sort-Object $_.FieldValues.PreservationDatePreserved -Descending

#Iterate through each item in the preservation hold library and restore to original location
ForEach($Item in $DeletedItems) {   
    Try {
        $OriginalURL = $Item.FieldValues.PreservationOriginalURL
        Write-host -f Yellow "Copying item:"$OriginalURL
       
        $SourceUrl = $Item.FieldValues.FileRef

        #Check if the File exists Already
        $FileExists = Get-PnPFile -Url $OriginalURL -ErrorAction SilentlyContinue
        
        If($FileExists)
        {
            Write-host -f Yellow "`tFile Already Exists!"   
        }
        Else
        {
            #Copy the file to its original location
            Copy-PnPFile -SourceUrl $SourceUrl -TargetUrl $OriginalURL -Force -ErrorAction Stop
            Write-host -f Green "`tFile Restored:" $OriginalURL
        }
    }
    Catch {
        Write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
}

This will restore all files by a specific user. Please ensure the parent document library exists already. Otherwise, you’ll see an error message: “Error: Folder ‘Document Library Name’ does not exists.”

Conclusion

To conclude, recovering files from a Preservation Hold library in SharePoint Online is a straightforward process that can be accomplished by following a few simple steps. First, navigate to the Preservation Hold library in your SharePoint Online site. From here, you can select the items you want to recover and use the “Copy” option. This will restore the deleted or modified items to the selected location in the site collection.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

9 thoughts on “SharePoint Online: How to Recover Deleted Files from Preservation Hold Library?

  • Hi, is there a way to automate this or maybe use PowerShell to restore the files to the original location? — the way Recycle Bin works?

    Reply
  • Had a user left and followed by the user account was deleted. If there is a legal hold (eDiscovery) on the user’s OneDrive how can we get to reservation hold library after the retention period of OneDrive. The OneDrive is not accessible anymore.

    Reply
  • Thanks for the info! Is there a easy way to restore LOTS of data from the preservation hold library back into exchange and onedrive?

    I was running out of onedrive space, deleted some things but that didn’t gain me any space, even after emptying 1st and 2nd recycle bins. Saw the 400GB in preservation hold folder. Didn’t find this page till after I found a page about changing retention policy. Changed that to 1 day and now loads of emails in inbox and files in active / not deleted folders in onedrive went away (hopefully into preservation hold folder?).

    I changed retention back to 12 years (can I delete the retention protocol? I don’t want active files not going away ever.).

    your instructions are showing me 30 items per page. And there’s tens of thousands of items. Next, next?

    And it seems it only allows download, not restore to onedrive.

    thoughts?

    Reply
  • In my tests, the space used for preservation old is substracted from the Onedrive space. Is it the same for you ?

    Reply
    • Of course, Yes! Any document library including preservation hold will occupy the storage space allocated.

      Reply
  • Great article as always.
    I must comment that we found out that its more advised to use retention label for SP rather than retention policy because of the versioning problem.
    once versioning is in place, and its in place be default by MS, and the site is under retention policy the versioning limit is not honored. even if you set 1 version for the library it will accumulate to 50,000 versions.
    Retention labels honors the versioning limits.

    Reply

Leave a Reply

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