How to Delete a SharePoint List using PowerShell?

Problem: A faulty solution installed on the SharePoint farm created duplicate lists in all sites in a large site collection with 100+ sites in it. We had to remove them all!

To delete a list from SharePoint, from the browser, we can go to: View All Site Content >> Click on “Remove” link from the context menu of the list. Alternatively, You can get into List Settings >> click on “Delete this list” to remove a list in SharePoint.

delete list from sharepoint powershell

However, There are 100+ sites where a particular list needs to be deleted.

Delete SharePoint list using PowerShell

PowerShell command to delete list in SharePoint:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site collection URL 
$SiteUrl="http://your-sharepoint-site" 
$ListName = "List-Name-To-Delete"

#Get Web and List objects
$web = Get-SPWeb $SiteURL
$list = $web.Lists[$ListName]

#Reset the "Allow Deletion" Flag
$list.AllowDeletion = $true
$list.Update()

$list.Delete()

write-host "List has been deleted successfully!"

One liner to delete a SharePoint list using PowerShell:

Get-SPWeb "http://Your-Site-URL" | Where-Object { $_.Lists.Delete([System.Guid]$_.Lists["Your-List-Name"].ID) }

SharePoint PowerShell to Delete List by GUID

Get-SPWeb "http://your-SharePoint-Site-URL" | Where-Object { $_.Lists.Delete([System.Guid]"{43c30f3a-f39a-4410-976c-a87bebb36e42}") }

Just replace the Web URL and GUID with yours and run the script.

Lets make a custom function to delete SharePoint list using PowerShell script.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom function to delete SharePoint list or document library using powershell
Function Delete-SPList
{
    param
    (
        [string]$WebURL  = $(throw "Please Enter the Web URL!"),
        [string]$ListName = $(throw "Please Enter the List Name to Delete!")
    )
    
    #Get the Objects 
    $Web = Get-SPWeb $WebURL
    $List = $Web.lists[$ListName]
 
    if($List)
    {
        #Set Allow Delete Flag
        $list.AllowDeletion = $true
        $list.Update()

        #delete list from sharepoint using powershell - Send List to Recycle bin
        $list.Recycle()
        
        #TO permanently delete a list, Use: 
        #$List.Delete()

        Write-Host "List: $($ListName) deleted successfully from: $($WebURL)"
    }
    else
    {
        Write-Host "List: $($ListName) doesn't exist at $($WebURL)"
    }
    $web.Dispose() 
}

#Call the function to delete list
Delete-SPList "http://intranet.crescent.com" "ConfigListv1"

So, call the function by looping through sites:

#Site URL variable
$SiteURL ="http://intranet.crescent.com" 

#get the site collection
$Site = Get-SPSite $SiteURL

#Loop through each site in the site collection
Foreach($web in $site.Allwebs)
{
    #Call the function to delete list
    Delete-SPList $web.URL "ConfigListv1"
}

Force delete corrupt SharePoint list using PowerShell:
In some cases, you need PowerShell’s help when you are unable to delete the list from SharePoint web UI as the list is corrupted and SharePoint won’t let you remove it, Use this script to remove the SharePoint list using PowerShell: Force delete corrupted list in SharePoint using PowerShell

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!

One thought on “How to Delete a SharePoint List using PowerShell?

Leave a Reply