Sunday, February 4, 2018

Delete SharePoint List/Library using PowerShell

Use below Power-Shell script to delete any SharePoint List/Library from site or sub site. Copy below code and save to text file with extension *.ps1 and run on SharePoint server using SharePoint Management Shell Tool.

# create spsite object using site url
$objSite = new-object Microsoft.SharePoint.SPSite("http://SHAREPOINT-SITE-URL") 

# create spweb object and open the site
$objWeb = $objSite.openweb()

# create list/library object with list/library name
$objList = $objWeb.Lists["<LIST/LIBRARY NAME>"] 

# set allow deletion = true if not done already
$objList.AllowDeletion = $True

# update list/library

# finally delete list/library

# print console
Write-Host "List/Library has been deleted...!"

No comments:

Post a Comment