Forum Discussion

luvsql's avatar
luvsql
Steel Contributor
Mar 05, 2020
Solved

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 though it's not on the page, it's still there in the SharePoint App and OneDrive App (click Libraries > page and it's still showing).

 

I've gone so far as to stop inheriting permissions and removed everything but it's still there for all users and causes lots of confusion.  I've even had to rename it (DO NOT USE) yet it looks really bad when everyone sees that.  It also shows in the Copy To and Move To areas of SharePoint for this page adding even more confusion.


Why can't it be removed on a page but it can on a classic site/subsite?

 

To clarify in Site Contents there is no remove option.  In library settings, there is no delete.  

  • Gaurav Goyal's avatar
    Gaurav Goyal
    Brass 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"
  • RobElliott's avatar
    RobElliott
    Silver Contributor

    luvsql there is the Delete this document library option in the Library Settings page which will work on the default Documents Library and delete it:

     

    Rob
    Los Gallardos
    Microsoft Power Automate Community Super User

Resources