Delete SharePoint 2013 List and Library using PowerShell


Today I will be sharing code to delete list and Libraries using PowerShell Script for SharePoint 2010 and SharePoint 2013. In my previous post, we discussed Create SharePoint 2013 List using out of box or custom template using PowerShell.


New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

Here we have a CSV file where SiteURL and ListName is presented and we will read from CSV file. Please Create CSV file with below columns.

  • SiteURL
  • ListName
Delete SharePoint 2013 List and Library using PowerShell
Delete SharePoint 2013 List and Library using PowerShell

Below Script you can use to delete list and libraries based on input CSV file. The PowerShell script, you can write, test and debug using Windows PowerShell ISE or by using Visual Studio code.



#Reading the CSV file
$path = “c:\ListAndLib.csv”
$csv = Import-csv -path $path

foreach($line in $csv)

{
#Reading content type related information
$siteURL = $line.SiteURL
$listName = $line.ListName

if ($siteURL -ne $null)
{
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) | Out-null
# Creating the instance for site
$web = Get-SPWeb $siteURL
$list = $web.Lists[$listName]

if($list -ne $null)
{
$web.Lists.Delete([System.Guid]$list.ID)
write-host -ForegroundColor Green $listname ” list has been deleted successfully….”
$web.Dispose()
}


}
}

Read some SharePoint PowerShell tutorials:

Thanks,
Sambita

Check out Best Alternative to InfoPath -> Try Now

FREE SHAREPOINT 2019 PDF

(Installation & Features)



About Sambita Rath

I have 9 years of exprience into SharePoint implementation, architecture, Administrator, development and Training.Designing Information Architecture in SharePoint 2007, 2010,2013 and Office 365.

View all posts by Sambita Rath →