Just came across this challenge and I thought I’ll document this.
Anyway the challenge is that some of the libraries and lists in SharePoint both online and on-premises might get “locked” for deletion, meaning you cannot delete them by any means, this is particullary through for “Record libraries”.
If you need to remove a “locked” library or list you must first unluck the list, for SharePoint Online this can be done using CSOM PowerShell
- Install the SharePoint Online SKD
- Use the following powershell to unlock the list/library
Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”
Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”
$siteURL = “your site”
$userId = “admin user UPN”
$pwd = ConvertTo-SecureString “password” -AsPlainText -Force
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$ctx.credentials = $creds
$list = $ctx.Web.Lists.GetByTitle(“RecordLibs”)
$list.AllowDeletion = $True #chaging to false will lock the list/library
$list.Description = “Updated with CSOM”