Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

SharePoint Online: Delete List using PowerShell CSOM

$
0
0
How to Delete a list or library in SharePoint Online:
  • Click on Site Settings gear >> Select Site contents from the menu.
  • On the site contents page, Hover over the list or library that you want to delete and then click the drop-down menu icon (…)
  • On the menu that appears, click on "Remove" link and then confirm the prompt to send the list to the Recycle Bin. 
  • Alternatively, you may remove a list or library in SharePoint online by going to list settings >> Click on "Delete this list" under Permissions and Management group.
    delete list sharepoint online powershell
Delete List in SharePoint Online using PowerShell:
#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"

#Set Variables for Site URL and List Name
$SiteURL= "https://crescent.sharepoint.com/sites/pmo"
$ListName="Projects"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred

#Get the List
$List=$Ctx.Web.Lists.GetByTitle($ListName)

#Delete the list
$List.DeleteObject()
$Ctx.ExecuteQuery()

Write-host -f Green "List Deleted Successfully!"
}
Catch {
write-host -f Red "Error deleting list!" $_.Exception.Message
}

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>