How to Delete a List in SharePoint Online using CSOM-PowerShell?

Requirement: Delete a list in SharePoint Online using PowerShell.

Important: Make sure, you have SharePoint Online client run time installed on the client machine before proceeding. Download it from here:

PowerShell Script to delete a List in SharePoint Online:

If you’ve ever needed to delete a list that’s no longer needed in SharePoint Online, you may use PowerShell instead of going through the web interface. In this article, we’ll show you how to use PowerShell to delete a list in SharePoint Online.

#Load SharePoint CSOM Assemblies
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"
##Variables for Processing
$SiteUrl = ""

#Get Credentials to connect
$Cred= Get-Credential

#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
$List = $Context.web.Lists.GetByTitle($ListName)
Write-Host "List deleted Successfully!"

Run it in PowerShell ISE:

delete list sharepoint online powershell

You can use this PowerShell to delete a document library as well in SharePoint Online. What if the list is protected from deletion? Well, You have to set the “AllowDeletion” property to enable delete. More info here: How to Delete a List in SharePoint Online using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

2 thoughts on “How to Delete a List in SharePoint Online using CSOM-PowerShell?

  • Hello I am Getting an Error
    Method invocation failed because [System.String] does not contain a method named ‘DeleteObject’.
    At line:17 char:2
    + $ListName.DeleteObject()
    + ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound


Leave a Reply

Your email address will not be published. Required fields are marked *