While deleting a SharePoint document library, sometimes the “SharePoint list cannot be deleted while on hold or retention period” issue occurs. It can be daunting if it occurs several times while you are performing a crucial task.
In SharePoint, whenever the data gets deleted then it is stored in the recycle bin. Along with that, a copy is also sent to the Preservation Hold Library. Due to this, you need to delete all files and subfolders first. But don’t fret now you will never face this issue again. In this detailed guide, we will discuss the complete process of resolving this issue. So, let’s get started.
Why You are Unable to Delete the List While it on Hold?
There are several reasons behind this error. Let’s take a look at them.
- Retention Policy Enforcement – SharePoint’s built-in feature of retention policy ensures the lists or libraries under a retention policy cannot be deleted. It preserves the content for the defined retention duration, even if the list is no longer used.
- Legal Hold or eDiscovery Hold – If a SharePoint site or a list is subject to a legal hold for some legal requirements, deletion of content is restricted in these cases.
- Compliance Settings – Microsoft Purview Compliance Center settings also may enforce preservation and restrict to deletion of content associated with sensitive data.
- Administrative Restrictions – The administrator can also add restrictions to prevent the data from being deleted.
How to Check if Your SharePoint Site is Under Hold?
You can follow the below steps to check if your SharePoint site is under hold.
- Open the SharePoint Settings.
- Now move to the Site Contents.
- Verify if there is a Preservation Hold Library.
If you have found it under the Hold, then move to the next section to resolve the SharePoint list cannot be deleted while on hold.
How to Delete Document Library in Retention Hold Using PnP PowerShell?
If your document library is under hold and you are unable to delete it. Then you can use the below PowerShell commands. It will delete the files and subfolders first and then delete the document library.
#Parameters $URL_of_Site = "Enter complete Site URL” $Name_of_the_list = "SalesDepartment" Connect-PnPOnline -URL $URL_of_Site -Credentials (Get-Credential) $Web = Get-PnPWeb $List = Get-PnPList -Identity $Name_of_the_list Function Empty-PnPFolder([Microsoft.SharePoint.Client.Folder]$Folder) { If($Folder.Context.web.ServerRelativeURL -eq "/") { $Folders_Site_Relative_URL = $Folder.ServerRelativeUrl } Else { $Folders_Site_Relative_URL = $Folder.ServerRelativeUrl.Replace($Folder.Context.web.ServerRelativeURL,[string]::Empty) } $Files = Get-PnPFolderItem -FolderSiteRelativeUrl $Folders_Site_Relative_URL -ItemType File ForEach ($File in $Files) { Remove-PnPFile -ServerRelativeUrl $File.ServerRelativeURL -Force -Recycle } $Sub_Folders = Get-PnPFolderItem -FolderSiteRelativeUrl $Folders_Site_Relative_URL -ItemType Folder Foreach($Sub_Folder in $Sub_Folders) { If( ($Sub_Folder.Name -ne "Forms") -and (-Not($Sub_Folder.Name.StartsWith("_")))) { Empty-PnPFolder -Folder $Sub_Folder $Parent_Folder_URL = $Folders_Site_Relative_URL.TrimStart("/") Remove-PnPFolder -Name $Sub_Folder.Name -Folder $Parent_Folder_URL -Force -Recycle Write-Host -f Green ("Deleted Folder: '{0}' at '{1}'" -f $Sub_Folder.Name, $Sub_Folder.ServerRelativeURL) } } } Empty-PnPFolder -Folder $List.RootFolder Remove-PnPList -Identity $Name_of_the_list -Recycle -Force
PnP Batch Method to Resolve SharePoint List Cannot Be Deleted While on Hold
Check another script to clear the files first and then the document library.
$SP_Site_URL = "Provide the Complete Site URL" $List_Name = "Marketing" Try { Connect-PnPOnline -Url $SP_Site_URL -Interactive $SP_List = Get-PnPList $List_Name $Item_Counter = $SP_List.ItemCount If($Item_Counter -eq 0) { Write-host "Document Library is Already Empty!" -f Yellow; Break} $global:count = 0 $ListItems = Get-PnPListItem -List $List_Name -PageSize 500 -Fields ID -ScriptBlock { Param($items) $global:count += $items.Count; Write-Progress -PercentComplete ` ($global:Count / $Item_Counter * 100) -Activity "Getting Items from List" -Status "Getting Items $global:Count of $($Item_Counter)"} Write-Progress -Activity "Completely Getting SharePoint List Items)" -Completed $Sorted_Items = $ListItems | Select-Object @{Name="ServerRelativeURL";Expression={$_.FieldValues.FileRef}}, ID | Sort-Object -Descending -Property ServerRelativeURL $Batch = New-PnPBatch ForEach ($Item in $Sorted_Items) { Remove-PnPListItem -List $List_Name -Identity $Item.ID -Recycle -Batch $Batch } Invoke-PnPBatch -Batch $Batch -Details Write-host -f Green "All of the Items in the Document Library has been deleted Successfully!" } Catch { write-host "Error Found” }
Using the above PowerShell commands you can resolve the SharePoint list deletion issues because of the hold or retention library . But do not forget to backup SharePoint Online to local storage before going to delete it. Because there might be further requirements to access the data. If you are managing another tenant or going to use, then you can migrate SharePoint site to another site using the SharePoint Migration Software.
Conclusion
In this detailed write-up, we have explained the mostly searched query SharePoint list cannot be deleted while on hold or retention period. Now you do not need to search the same query again. Also, do not forget to store the list items before deletion.