Clear the SharePoint Preservation Hold Library

I recently ran into a SharePoint storage problem that took a while to get to the bottom of, and it ended with me needing to clear the SharePoint Preservation Hold Library. We’d deleted a significant amount of data from a site and emptied the recycle bins, but the storage usage wasn’t dropping the way I expected. That made me start looking at where the storage was actually going, and that’s when I found the Preservation Hold Library (PHL).

If you haven’t dealt with it before, the PHL is a hidden SharePoint system library that Microsoft 365 uses to retain content when retention policies or other compliance requirements apply. It can get surprisingly large. In our case, it had grown to around 800 GB on a site using about 1.2 TB of storage. That explained why deleting files from the normal libraries wasn’t having the effect I expected: much of the data wasn’t actually disappearing, because SharePoint was retaining it under the retention configuration.

This article walks through how I found the problem, how I measured the library, how I worked out why the data was being retained, and the options for dealing with it, from letting Microsoft 365 clean up on its own through to the PowerShell approach I used.

What is the Preservation Hold Library?

The Preservation Hold Library is a hidden system library that SharePoint creates automatically when a retention policy applies to a site, when a retention label set to retain content is used, or when an eDiscovery hold is in place.

When users modify or delete files that are under retention, SharePoint doesn’t simply remove the original. According to Microsoft’s documentation on retention for SharePoint and OneDrive, a copy is kept in the Preservation Hold Library until the retention period expires. The user believes the file is gone, but the storage is still being consumed. That design ensures compliance, but it comes at a cost.

Why the library can become so large

On a busy site, everyday collaboration can create a lot of retained data, because users are constantly creating, modifying, replacing, moving and deleting files and uploading new versions. When retention applies, much of that activity results in preserved copies. The problem is most noticeable on sites that have been under retention for a long time or have had a lot of file churn.

Other situations that contribute include large migration projects, temporary project data, retention policies applied broadly across a tenant, retention policies being changed or removed, heavy document versioning, and sites that have simply been well used for years. The result can be a site where users appear to have cleaned everything up while a large amount of retained data sits behind the scenes.

Important warning: this is a permanent action

Before going any further, this needs to be crystal clear. Deleting content from the Preservation Hold Library permanently removes retained data and bypasses the recycle bin.

Only proceed if the retention policy has been removed or has expired, your legal, compliance and records teams have approved the deletion, and you understand the regulatory implications for your organisation. In regulated industries such as finance, health and government, this step should be formally documented and approved.

First step: confirm the library is actually using the storage

Before deleting anything, prove that the Preservation Hold Library is the problem. SharePoint storage can also be consumed by document versions, recycle bins, Teams files, Site Assets, large media files, other libraries and archived project data. Don’t assume the PHL is responsible just because the site has a retention policy.

Check the site’s storage

Start in the SharePoint admin centre, review the storage used by the affected site, and record the figure. In my case that was 1.20 TB. You can then compare it with the size of the Preservation Hold Library.

Measure the Preservation Hold Library

Connect to the site with PnP.PowerShell (covered below) and run Get-PnPFolderStorageMetric against the library:

powershell

Get-PnPFolderStorageMetric -List "Preservation Hold Library"

Here’s what my figures looked like:

Site storage:                 1.20 TB
Preservation Hold Library:    800 GB

At that point you have a strong indication that retained data is contributing significantly to the storage problem.

View the library directly

The Preservation Hold Library is hidden from normal SharePoint navigation, but if you have appropriate administrative permissions you can browse to it directly:

https://tenant.sharepoint.com/sites/SiteName/PreservationHoldLibrary

Replace tenant and SiteName with your own values. This is useful for confirming the library exists and getting a feel for the type and volume of content being retained. Treat it as a system compliance location, not an ordinary document library.

Find out why the content is being retained

Finding a large PHL is only half the investigation. The next question is what retention policy or hold is causing the content to be kept. Before removing anything, check Microsoft Purview for retention policies, retention labels, eDiscovery holds and any other compliance controls that apply to the site.

A site may be affected by more than one retention mechanism, so don’t assume that removing a single policy automatically makes all retained content eligible for deletion. This is also where you need to involve your compliance, records or legal teams.

The safer option: let Microsoft 365 handle the cleanup

If the retention requirement has ended, the preferred approach is to remove the site from the applicable retention scope and let Microsoft 365’s retention processing deal with the expired content. That’s considerably safer than trying to empty the library yourself.

It’s important to set expectations, because the storage won’t drop straight away. Microsoft documents that a timer job evaluates content that has been in the Preservation Hold Library for more than 30 days, and that the job runs every seven days, so it can take up to 37 days for eligible content to leave the library. If you release a retention policy entirely, there’s also a 30-day grace period during which cleanup is suspended, in case the change was a mistake. Microsoft Q&A answers and admin guides note that excluding a specific site from a policy you’re keeping avoids that grace period.

So removing a retention policy today doesn’t mean hundreds of gigabytes will disappear tomorrow. If the content is genuinely no longer required, give the retention process time to complete before considering anything more aggressive.

Priority cleanup in Microsoft Purview

There’s now a supported option for deleting retained content early. Microsoft Purview’s priority cleanup for OneDrive and SharePoint lets you override existing retention settings or eDiscovery holds to delete content, under Data Lifecycle Management. It requires the Priority Cleanup Admin role, a simulation run before the policy can be enforced, and approval from other admins. That’s deliberate: deleting retained data is a decision that should never rest with one person.

If you need content gone before normal retention processing would remove it, priority cleanup should be your first choice, because it keeps the decision, approvals and audit trail inside Purview. Check your licensing first, as it sits within Purview’s compliance features.

When manual cleanup might be justified

There are situations where manual cleanup with PowerShell may still be considered. Typically that’s when the retention policy has been removed, the site is no longer under any hold, compliance has confirmed the content can go, the normal retention processing period has passed, storage is still unexpectedly high, and priority cleanup isn’t available to you or doesn’t fit the situation. You should also have documented approval for the action.

PowerShell is useful for inspecting and administering SharePoint content. Just be clear about the difference between what PowerShell can technically attempt and Microsoft’s documented retention workflow. The Preservation Hold Library is a compliance mechanism, not an ordinary library you empty whenever storage gets high, and SharePoint will refuse to delete anything that’s still subject to retention.

Connecting to SharePoint with current PnP.PowerShell

Older PnP.PowerShell examples often connect with Connect-PnPOnline -Url $SiteUrl -Interactive and nothing else. On current versions, interactive login requires your own Entra ID application registration, so copying an old script will often fail with an authentication error before it reaches SharePoint.

Install the module if you need to:

powershell

Install-Module PnP.PowerShell -Scope CurrentUser

PnP’s guide to registering an Entra ID application covers both options. The quickest is the built-in cmdlet:

powershell

Register-PnPEntraIDAppForInteractiveLogin `
    -ApplicationName "PnP SharePoint Admin" `
    -Tenant "tenant.onmicrosoft.com"

Alternatively, register the application yourself in Microsoft Entra ID and grant the SharePoint permissions your organisation’s security requirements allow. Once you have the application (client) ID, connect with:

powershell

Connect-PnPOnline `
    -Url $SiteUrl `
    -Interactive `
    -ClientId "YOUR-ENTRA-APP-CLIENT-ID"

Test the connection before attempting any cleanup. If authentication doesn’t work, there’s no point troubleshooting the deletion script.

Inspect the library with PowerShell

Once connected, measure the library and get a count of what’s in it:

powershell

$LibraryName = "Preservation Hold Library"

Get-PnPFolderStorageMetric -List $LibraryName

$items = Get-PnPListItem -List $LibraryName -PageSize 500
$items | Group-Object FileSystemObjectType | Select-Object Name, Count

It’s worth understanding how -PageSize works. A value of 500 means PnP retrieves results from SharePoint in pages of up to 500 items, which keeps each request under SharePoint’s list view threshold. It doesn’t mean Get-PnPListItem stops after 500 items. It keeps paging until it has retrieved the whole library.

PowerShell script: process the Preservation Hold Library

If your organisation has explicitly approved direct administrative cleanup, the following script provides a controlled way to do it. It connects using the current PnP authentication method, measures the library before starting, and requires typed confirmation. It then deletes files before folders, newest first, so that folder deletions don’t remove items that are still queued. It counts successes and failures, reports progress, and exports any failures to a CSV for your records.

powershell

$SiteUrl     = "https://tenant.sharepoint.com/sites/SiteName"
$ClientId    = "YOUR-ENTRA-APP-CLIENT-ID"
$LibraryName = "Preservation Hold Library"
$PageSize    = 500
$FailureLog  = ".\PHL-failures-$(Get-Date -Format yyyyMMdd-HHmm).csv"

Connect-PnPOnline `
    -Url $SiteUrl `
    -Interactive `
    -ClientId $ClientId `
    -ErrorAction Stop

Write-Host "Connected to $SiteUrl" -ForegroundColor Green

# Record storage before starting
Write-Host "`nCurrent Preservation Hold Library storage:" -ForegroundColor Cyan
Get-PnPFolderStorageMetric -List $LibraryName | Format-List

# Retrieve every item first, rather than deleting while paging through the library
Write-Host "Retrieving items..." -ForegroundColor Cyan
$items = Get-PnPListItem -List $LibraryName -PageSize $PageSize

# Files first, then folders, newest first within each group
$queue = $items | Sort-Object `
    @{ Expression = { $_.FileSystemObjectType -eq "Folder" } },
    @{ Expression = "Id"; Descending = $true }

Write-Host "Found $($queue.Count) items." -ForegroundColor Cyan
Write-Host ""
Write-Host "WARNING: This permanently deletes retained content and bypasses the recycle bin." -ForegroundColor Red
Write-Host "Only continue if all retention, legal and compliance requirements have been cleared." -ForegroundColor Yellow

$confirm = Read-Host "Type DELETE to continue"

if ($confirm -ne "DELETE") {
    Write-Host "Operation cancelled." -ForegroundColor Yellow
    Disconnect-PnPOnline
    return
}

$deleted  = 0
$failures = @()

foreach ($item in $queue) {
    try {
        # Without -Recycle, Remove-PnPListItem deletes permanently
        Remove-PnPListItem `
            -List $LibraryName `
            -Identity $item.Id `
            -Force `
            -ErrorAction Stop

        $deleted++

        if (($deleted % 100) -eq 0) {
            Write-Host "Deleted $deleted of $($queue.Count)..." -ForegroundColor Gray
        }
    }
    catch {
        # Inside catch, $_ is the error, so use $item for the list item details
        $failures += [pscustomobject]@{
            Id    = $item.Id
            Type  = $item.FileSystemObjectType
            Error = $_.Exception.Message
        }
        Write-Host "Failed to delete item $($item.Id): $($_.Exception.Message)" -ForegroundColor Red
    }
}

Write-Host ""
Write-Host "Processing complete." -ForegroundColor Green
Write-Host "Deleted: $deleted"
Write-Host "Failed:  $($failures.Count)"

if ($failures.Count -gt 0) {
    $failures | Export-Csv -Path $FailureLog -NoTypeInformation
    Write-Host "Failures written to $FailureLog" -ForegroundColor Yellow
}

Disconnect-PnPOnline

What the script is doing

The script retrieves the full list of items before deleting anything, rather than removing items from the library while it’s still paging through it. That avoids the paging position shifting underneath it partway through the run.

Files are deleted before folders because deleting a folder removes everything inside it, which would make any items still queued in that folder fail. Processing newest first within each group follows the same principle.

Remove-PnPListItem deletes permanently unless you add -Recycle, so there’s no recycle bin step. That doesn’t override Microsoft’s retention protections, though. If SharePoint decides content still has to be retained, the deletion fails, and the failure CSV records which items and why. That’s another reason the compliance and retention investigation has to come first.

How to run the script

Save the script as Clear-PreservationHoldLibrary.ps1, open PowerShell with an account that has appropriate SharePoint permissions, and run:

powershell

.\Clear-PreservationHoldLibrary.ps1

The script connects to the site, shows the current storage metrics and item count, and asks you to type DELETE before it processes anything. Don’t automate that confirmation away in production unless your change-control process specifically calls for it.

Monitor the cleanup

Large libraries can hold thousands or even hundreds of thousands of items. If you run into throttling or transient failures, reduce the page size (for example from 500 to 200), run the job during quieter periods, and keep an eye on the failure count. Investigate repeated failures rather than simply rerunning the script, because a pattern of failures often points to content that’s still under retention.

Verify the result

Don’t finish the job when PowerShell says “Processing complete”. Measure the environment again, and record the site storage, the library’s storage and item count, the recycle bin contents and any remaining retention or hold configuration:

powershell

Get-PnPFolderStorageMetric -List "Preservation Hold Library"

Keep in mind that SharePoint’s storage reporting can take time to catch up. If you used retention processing rather than the script, check the second-stage recycle bin as well, because Microsoft documents that expired content passes through the recycle bins before it’s permanently removed, and it still counts towards site storage while it’s there. Keep your before and after figures so you can show exactly what changed.

Always document the change

Treat the removal of retained content with the same care you’d apply to deleting backups or other critical business data. Record the affected site, the original site and PHL storage figures, the retention policy or hold that caused the retention, why the content became eligible for removal, the compliance or records approval, the date and time of the change, the number of items processed and failed, and the storage figures afterwards. Keep the failure CSV with that record. It gives you an audit trail if the decision is ever questioned.

When you shouldn’t use this script

Don’t attempt direct cleanup if a retention policy still applies, retention labels are still protecting the content, an eDiscovery or legal hold is active, or litigation or regulatory requirements are ongoing. Hold off as well if you’re unsure why the content exists, if compliance or records haven’t approved the action, if priority cleanup is available and suitable, or if you haven’t confirmed that the library is actually responsible for the storage problem. The Preservation Hold Library is a compliance mechanism, not a second recycle bin.

Compliance first, cleanup second

The Preservation Hold Library works exactly as Microsoft designed it, but it can still catch IT teams off guard. The lesson is that a SharePoint storage problem should be diagnosed before it’s treated. Find where the storage is going, confirm whether the library is responsible, and work out which policy, label or hold is retaining the content. If the requirement has ended, let Microsoft’s retention processing or priority cleanup do the work. Consider direct intervention only after that investigation is done and the right approvals are in place.

In my case, the investigation showed 800 GB of storage tied up in the Preservation Hold Library. Once the retention requirements were cleared and the cleanup was complete, that 800 GB was recovered. SharePoint retention was doing its job. The challenge for administrators is understanding what it’s retaining, where that data lives, and when it’s legitimately safe for it to go.

Preservation Hold Library cleanup checklist

  1. Record the site’s current storage in the SharePoint admin centre.
  2. Measure the Preservation Hold Library with Get-PnPFolderStorageMetric and confirm it accounts for a significant share of that storage.
  3. Identify every retention policy, retention label and eDiscovery hold that applies to the site in Microsoft Purview.
  4. Get written approval from compliance, records or legal before changing anything.
  5. Remove the site from the retention scope, preferably by excluding it, and allow up to 37 days, or longer if a released policy’s 30-day grace period applies.
  6. If content has to go sooner, use Purview priority cleanup and its approval workflow.
  7. Only if neither option fits, and with approval documented, run the PowerShell script with your own Entra app registration.
  8. Re-measure site storage, PHL storage and both recycle bin stages, and allow time for storage reporting to catch up.
  9. File the before and after figures, approvals and failure log as your audit record.

Microsoft references

Leave a Reply

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