Hello @Pekka Pekkonen ,
One possible reason for this is that SharePoint has a default limit of 5000 items that can be deleted at once.
However, there are several ways to delete items in bulk from a SharePoint list:
1.You can delete items in batches, making sure the number is under 5000 at a time.
2.PowerShell: You can use PowerShell to delete all items from a SharePoint list.
PowerShell to Delete All Items from Large Lists in SharePoint Online:
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Config Parameters
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
$BatchSize = 500
#Setup Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Get the web and List
$Web = $Ctx.Web
$List=$web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
Write-host "Total Number of Items Found in the List:"$List.ItemCount
#Define CAML Query to get list items in batches
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "<View Scope='RecursiveAll'><RowLimit Paged='TRUE'>$BatchSize</RowLimit></View>"
Do {
#Get items from the list in batches
$ListItems = $List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
#Exit from Loop if No items found
If($ListItems.count -eq 0) { Break; }
Write-host Deleting $($ListItems.count) Items from the List...
#Loop through each item and delete
ForEach($Item in $ListItems)
{
#Delete SharePoint list items
$List.GetItemById($Item.Id).DeleteObject()
}
$Ctx.ExecuteQuery()
} While ($True)
Write-host -f Green "All Items Deleted!"
}
Catch {
write-host -f Red "Error Deleting List Items!" $_.Exception.Message
}
Remember to replace the variable $SiteURL, $ListName with your own.
For more detail information:https://www.sharepointdiary.com/2015/10/delete-all-list-items-in-sharepoint-online-using-powershell.html#:~:text=SharePoint%20Online%3A%20Delete%20All%20List%20Items%20using%20PowerShell,item%20will%20be%20sent%20to%20the%20recycle%20bin
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
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.