SharePoint Online: How to Disable “Delete this list”?

Requirement: Disable delete on a SharePoint Online List or Document Library.

How to Disable Delete options for List or Document Library in SharePoint Online?

We have a requirement to disable any accidental deletes on certain SharePoint Online lists and document libraries that are provisioned as part of a custom application. If you have noticed, in some SharePoint lists & libraries (E.g. “Farm Templates” library), “Delete this List” or “Delete this Document Library” links are missing by default to prevent the delete option. So, How do we disable delete options?

Well, if you want to disable the delete list option from list settings in SharePoint (and in other places too!), you can set “AllowDeletion” property of the List or Library to “False”. Once this is set, delete options go hidden!

sharepoint online disable delete this list

PowerShell to Disable Delete in SharePoint Online List

Let’s turn “Allow Delete” flag to false to prevent deletion.

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

#Set Parameters for Site URL and List Name
$SiteURL= ""
$ListName= "config"
#Setup Credentials to connect
$Cred = Get-Credential
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    #Get the List
    #disable delete in sharepoint online list
    $List.AllowDeletion = $False
    Write-host -f Green "List Settings Updated Successfully!"
Catch {
    write-host -f Red "Error Updating List Settings!" $_.Exception.Message

This script hides delete options from the given list in places such as list settings, etc. Similarly, we can disable delete options for SharePoint Online document libraries as well. Let’s use PnP PowerShell this time:

#Set Parameters
$SiteURL = ""
$ListName = "Inventory"

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -UseWebLogin

#Disable delete in sharepoint online document library
$List = Get-PnPList -Identity $ListName -Includes AllowDeletion
$List.AllowDeletion = $False

SharePoint Online Can’t Delete List?
Once the “AllowDeletion” flag is set to false, we can’t delete the list neither through web UI nor PowerShell, until we revert the flag to “True”! You will get “This list cannot be deleted.” error if you try to delete it. if you must delete a list that doesn’t provide “Delete this list” link.

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply