Forum Discussion
luvsql
Mar 05, 2020Iron Contributor
Unable to Delete Default Document Library from Sharepoint Page
I've created a new page in SharePoint Online. I always create a NEW document library so they all have unique names. There is NO option to remove or delete the default one called Documents. Even th...
- Mar 07, 2020
luvsql then your site must be connected to an Office 365 Group. Sites that aren't connected to an Office 365 Group DO have the delete this Document Library link on the default Document Library as in my previous screenshot. All my sites which are not connected to an Office 365 Group DO have the link. Sites that are connected to an Office 365 Group do not.
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Gaurav Goyal
Feb 03, 2022Brass Contributor
Hi,
You can use following code to delete the library as well :
#Custom function to delete a SharePoint Online document library using powershell
Function Delete-SPODocumentLibrary
{
param
(
[string]$SiteURL = $(throw "Please Enter the Site URL!"),
[string]$LibraryName = $(throw "Please Enter the Library Name to Delete!")
)
Try {
#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Document Library and set allow deletion flag
$Library=$Ctx.Web.Lists.GetByTitle($LibraryName)
$Library.AllowDeletion = $True
$library.Update()
$Ctx.ExecuteQuery()
#Delete the Document Library - Send to Recycle bin
$Library.Recycle() | Out-Null #To permanently delete, call: $Library.DeleteObject()
$Ctx.ExecuteQuery()
Write-Host "Document Library: '$LibraryName' has been Deleted Successfully!" -ForegroundColor Green
}
Catch {
write-host -f Red "Error Deleting Document Library!" $_.Exception.Message
}
}
#Call the function to delete a document library
Delete-SPODocumentLibrary -SiteURL "https://mytenant.sharepoint.com/sites/Portal-Dev/" -LibraryName "Portal - Dev Documents"
You can use following code to delete the library as well :
#Custom function to delete a SharePoint Online document library using powershell
Function Delete-SPODocumentLibrary
{
param
(
[string]$SiteURL = $(throw "Please Enter the Site URL!"),
[string]$LibraryName = $(throw "Please Enter the Library Name to Delete!")
)
Try {
#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Document Library and set allow deletion flag
$Library=$Ctx.Web.Lists.GetByTitle($LibraryName)
$Library.AllowDeletion = $True
$library.Update()
$Ctx.ExecuteQuery()
#Delete the Document Library - Send to Recycle bin
$Library.Recycle() | Out-Null #To permanently delete, call: $Library.DeleteObject()
$Ctx.ExecuteQuery()
Write-Host "Document Library: '$LibraryName' has been Deleted Successfully!" -ForegroundColor Green
}
Catch {
write-host -f Red "Error Deleting Document Library!" $_.Exception.Message
}
}
#Call the function to delete a document library
Delete-SPODocumentLibrary -SiteURL "https://mytenant.sharepoint.com/sites/Portal-Dev/" -LibraryName "Portal - Dev Documents"