Delete SharePoint 2013 List and Library using PowerShell

InfoPath alternatives for form designing SharePoint

Today I will be sharing code to delete list and Libraries using PowerShell Script for SharePoint 2010 and SharePoint 2013.

Also you can check out previous posts on:
– Create Site Collection PowerShell Script SharePoint 2013 or 2010

– Get List Items SPServices Office 365 Sharepoint 2013

– Create View in lists or libraries CSOM PowerShell Office 365 SharePoint 2013

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.

#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()
}

}
}

Thanks,
Sambita

Similar SharePoint 2013 Tutorials


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 →

Leave a Reply