The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
1.Delete all document libraries at once.
$SiteURL = "https://tenant.sharepoint.com/sites/test"
Connect-PnPOnline -Url $SiteURL -Interactive
$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")
$Libraries = Get-PnPList | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $false -and $ExcludedLibraries -notcontains $_.Title}
ForEach($Library in $Libraries)
{
#Delete document library in sharepoint online using powershell
Remove-PnPList -Identity $Library -Recycle -Force
Write-host -f Green "Library '$($Library.Title)' Deleted Successfully!"
}
2.Delete document libraries based on CSV file with library names.
Create a CSV file then run following PowerShell.
$SiteURL = "https://tenant.sharepoint.com/sites/test"
$CSVFilePath = "C:\Libraries.csv"
Connect-PnPOnline -Url $SiteURL -Interactive
$CSVFile = Import-CSV $CSVFilePath
ForEach($Row in $CSVFile)
{
Remove-PnPList -Identity $Row.LibraryName -Force -recycle
Write-host -f Green "Document Library '$($Row.LibraryName)' Deleted Successfully!"
}
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.