Share via

Bulk deleting SharePoint Libraries via PowerShell & CSV

Somsak Narong 20 Reputation points
2026-04-06T01:39:59.73+00:00

How can I bulk delete multiple document libraries, either entirely or from a CSV list while automatically excluding system-protected libraries like "Site Assets" to prevent site corruption?

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

Answer accepted by question author
  1. Teddie-D 13,985 Reputation points Microsoft External Staff Moderator
    2026-04-06T03:17:29.28+00:00

    Hi @Somsak Narong 

    To bulk delete SharePoint document libraries, you’ll first need to connect to your site using PnP PowerShell. Follow the official guide here: Register an Entra ID Application to use with PnP PowerShell | PnP PowerShell.

    When you reach the step in the article for assigning permissions, choose either AllSites.Manage or AllSites.FullControl to ensure you can manage libraries with PnP commands. For a smoother setup experience, it’s recommended to use PowerShell 7.5.

    User's image

    1.Delete all on-system document libraries at once.

    Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive -ClientID <your application ID> 
    $ExcludedLibraries = @( 
        "Converted Forms","Master Page Gallery","Customized Reports","Form Templates", 
        "Site Collection Documents","Site Collection Images","Reporting Templates", 
        "Solution Gallery","Style Library","Web Part Gallery", 
        "Site Assets","wfpub","Site Pages","Images","Documents" 
    ) 
      
    # Get all document libraries (excluding system ones) 
    $Libraries = Get-PnPList | Where-Object { 
        $_.BaseType -eq "DocumentLibrary" -and 
        $_.Hidden -eq $false -and 
        $_.IsSystemList -ne $true -and 
        $_.IsCatalog -eq $false -and 
        $ExcludedLibraries -notcontains $_.Title 
    } 
      
    # Delete each library safely 
    ForEach($Library in $Libraries) { 
        try { 
            Remove-PnPList -Identity $Library -Recycle -Force -ErrorAction Stop 
            Write-Host "Library '$($Library.Title)' Deleted Successfully!" -ForegroundColor Green 
        } 
        catch { 
            Write-Host "Skipped '$($Library.Title)' - $($_.Exception.Message)" -ForegroundColor Yellow 
        } 
    } 
    

    2.Delete Libraries Based on a CSV List 

    Prepare a CSV file with a column named LibraryName listing the libraries you want to delete. 

    LIbraryName
    Library A
    Library B
    $CSVFilePath = "C:\folder\BulkDeleteLibraries.csv" 
    Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive -ClientID <your application ID>   
    
    Import-Csv $CSVFilePath | ForEach-Object {
        try {
            Remove-PnPList -Identity $_.LibraryName -Recycle -Force -ErrorAction Stop
            Write-Host "Deleted: $($_.LibraryName)" -ForegroundColor Green
        }
        catch {
            Write-Host "Skipped or Failed: $($_.LibraryName)" -ForegroundColor Yellow
        }
    }
    

    I hope this helps. 


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".   

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.  


1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-04-06T01:40:10.7666667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Bulk deletion of document libraries while safely excluding system libraries is not documented in the provided context. The context only covers:

    • Deleting files, folders, or links inside a document library via the SharePoint UI
    • Alternate UI methods to delete files/folders and restore them from the Recycle Bin
    • Removing a tenant-wide Org Assets library designation with Remove-SPOOrgAssetsLibrary (this does not delete the library itself)

    From the context, the only relevant automation cmdlet is:

    Remove-SPOOrgAssetsLibrary -ListId 58454454-6546-6466-9769-646464623988
    

    This cmdlet:

    • Removes a library as an organization assets library so it no longer appears under the “Your organization” tab in file pickers.
    • Does not delete the underlying SharePoint document library.
    • Accepts either -LibraryUrl or -ListId, and supports -WhatIf and -Confirm.

    The context does not provide:

    • Any PowerShell cmdlet or pattern for deleting multiple document libraries in bulk.
    • Any documented list of “system-protected” libraries (such as “Site Assets”) or a supported way to automatically exclude them.
    • Any CSV-driven example for bulk library deletion.

    Because of this, no supported, context-based script can be given for bulk deleting document libraries or for safely excluding system libraries.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.