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:
#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 = ""

$UserName="[email protected]"
$Password ="Password goes here"
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
$Context.Credentials = $credentials
#Get the List
$List = $Context.web.Lists.GetByTitle($ListName)
Write-Host "List deleted Successfully!"

Run it in PowerShell ISE:
delete list sharepoint online powershell


  1. 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

    1. Change $ListName.DeleteObject() to $List.DeleteObject()


Please Login and comment to get your questions answered!

Powered by Blogger.