Sharepoint – Unlock and Delete a locked Library


To totally unlock this section you need to Log-in

Sometimes, 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 particularly through for Record libraries. Record libraries are essentially document libraries that you create to classify and store important records. You create a record library for each type of record you want to retain. Records are automatically routed to the appropriate library based on the settings configured in the Content Organizer.

To unlock/delete these locked libraries or lists you must first unlock the list, and for SharePoint Online and on-premise versions this can be done using CSOM PowerShell, but first we will need to install the SharePoint Client Components SDK and use the following Powershell code to unlock the specific 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"

$shareURL = "Sharepoint Site"
$username = "Admin-UPN"
$pwd = ConvertTo-SecureString "password" -AsPlainText -Force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $pwd)
$context = New-Object Microsoft.SharePoint.Client.ClientContext($shareURL)
$context.credentials = $credentials
$list = $context.Web.Lists.GetByTitle("LockedListLibraryName")
$context.load($list)
$list.AllowDeletion = $True ### Chaging this property to False will lock the list/library.
$list.Description = "Updated with CSOM"
$list.Update()
$context.executeQuery()

If the locked library, when trying to delete it, is like the following you can try the following procedure to try to avoid using Powershell code to unlock and enable again the capability to delete it.

Sharepoint - Unlock and Delete a locked Library

This kind of error/issue could means that there are still documents in the library that have not yet had a major version published. To the person trying to delete the folder (or the library), it looks empty. What you need to do is go into the Library Settings and take ownership of the files. You can then delete the entries, and after that the folder can be deleted.

The path to follow on Sharepoint is the following: Library Tools > Library > Library Settings > Permissions and Management > Manage files which have no checked in version.

Sharepoint - Unlock and Delete a locked Library

Then select all the remaining files and take the ownership and after that delete them to unlock the library and be able again to delete it (if needed).

Sharepoint - Unlock and Delete a locked Library