Remove delete option on a document library
This sample script will show you how to remove the delete option on a document library to prevent users from accidentally deleting libraries if the have the "edit" permission. The script will not prevent deletions rather, just disable the UI option.
Connect-PnPOnline -Url "https://<tenant>.sharepoint.com" -Interactive $list = Get-PnPList -Identity "<list or library>" $list.AllowDeletion = $false $list.Update() Invoke-PnPQuery Write-Host "Done! :-)" -ForegroundColor Green
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
Sample first appeared on Prevent document library deletion | CaPa Creative Ltd
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.