Wednesday, October 19, 2016

SharePoint Online: Delete List using PowerShell CSOM

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
Now, lets delete list in sharepoint online using PowerShell

Delete List in SharePoint Online using PowerShell:
SharePoint online PowerShell to delete list
#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
}



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!


You might also like:

Related Posts Plugin for WordPress, Blogger...