Get Preservation Library
This PnP PowerShell script checks whether a Preservation Hold Library exists on a SharePoint site and reports how many items it contains. The Preservation Hold Library is created automatically when a Microsoft Purview retention policy is applied to a site and is not visible to standard users, but counts toward the site's storage quota.
Purpose
Use this script to:
- Confirm whether a retention policy has triggered a Preservation Hold Library on a site
- Get an item count as an indicator of retention activity on the site
- Support storage investigations where high consumption cannot be explained by visible content
- Identify sites with active compliance holds before running version trimming operations
Prerequisites
- PnP PowerShell module installed
- SharePoint Online Admin permissions or Site Collection Administrator rights
- An Azure AD app registration with a client ID (for
-ClientIdauthentication)
PowerShell Script
$clientId = ""
Connect-PnPOnline -Url "https://tenantName.sharepoint.com/sites/siteName" -ClientId $clientId -Interactive
$list = Get-PnPList -Identity "Preservation Hold Library" -ErrorAction SilentlyContinue
if ($list) {
$items = Get-PnPListItem -List "Preservation Hold Library" -PageSize 500
Write-Host "Preservation Hold Library found. Item count: $($items.Count)"
} else {
Write-Host "No Preservation Hold Library found on this site"
}
Usage Notes
- Replace
tenantNameandsiteNamewith your actual tenant and site values - Enter your Azure AD app registration client ID in the
$clientIdvariable - Content in the Preservation Hold Library cannot be manually deleted while a retention policy is active — it is cleared automatically when the retention period expires
- Run this script before version trimming operations to understand whether retained content will limit the trim
- If no Preservation Hold Library is found, the site either has no active retention policy or the library has not yet been triggered