Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Thursday, June 13, 2019 9:05 PM
Does anyone know of a good powershell command that can delete the contents of a large SPO library? I've tried deleting it it through the gui, and get the "This exceeds the list view threshhold" error. No kidding it exceeds the threshold, by a few million items. I even tried to delete the entire site and still got that same error. Why in the world would a list view threshhold come up when deleting a site?
I tried using Sharegates's delete tool, but it seems to choke on that error.
I called MS and they wanted me to create a new view, limit it to 5,000 items, and then put in ID 0 as a start, and 4,999 as the end, and then manually delete all that were returned. Then I was supposed to change the start ID to 5,000, and the end to 9,999, and keep doing that for all couple million items.
I"m not kidding, that was Microsoft's official solution to this problem. Even when I pushed to get someone higher up the line.
So I told them to close the ticket and I'd figure out a way to do it with powershell. The problem is that when I find stuff with powershell it always refers to on prem stuff, not SPO, and that little detail makes me nervous. I assume that there would be some kind of throttling going on if I try to grab a couple million entries 1 by one and whack them.
Does anyone know of a nice SAFE powershell script that will grab 5,000 in a chunk, delete them, then grab 5,000 more and so on?
Thanks in advance.
Ted
Friday, June 14, 2019 7:57 AM
Hi, Ted,
Here are some scripts you can take as references:
https://www.crowcanyon.help/article/338/
For your issue, you can also write a batch file to a simple delete file script repeatedly.
Best Regards
Jerry
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
SharePoint Server 2019 has been released, you can click
here to download it.
Click
here to learn new features. Visit the dedicated
forum to share, explore and talk to experts about SharePoint Server 2019.
Friday, June 14, 2019 9:19 AM
Hi Ted,
Recently i was involved to delete a huge amount of list item (more than 5 lakh items) from my SharePoint On-premises server and it took nearly six days to delete all the item from that list and i have executed the below mentioned powershell script from my workstation computer since i don't have permission on the SharePoint servers.
So you can use the same template to delete the item from your sharepoint online list
Cls
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"
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext "https://siteurl"
$listname ="List Name"
Do
{
$web = $clientContext.Site.RootWeb
$clientContext.Load($web)
$clientContext.ExecuteQuery()
$list=$clientContext.Web.Lists.GetByTitle($listname)
$clientContext.Load($list)
$clientContext.ExecuteQuery()
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml=”<View><RowLimit>5000</RowLimit></View>”
$items=$list.GetItems($query)
$clientContext.Load($items)
$clientContext.ExecuteQuery()
if ($items.Count -gt 0)
{
for ($i = $items.Count-1; $i -ge 0; $i–-)
{
$items[$i].DeleteObject()
write-host $items[$i] deleted + $i
}
$clientContext.ExecuteQuery()
write-host "Operations Completed"
Clear-host
}
}
While($items.Count -eq 0)
{
Write-Host "All Items are deleted in the List" -ForegroundColor Green
}
_______________________
Thivagar SEGAR
[If this Post helps you, then please don't forget to mark it answer or Vote for this post]
Friday, June 14, 2019 4:33 PM
The 2nd one looked like a perfect fit, and I downloaded his linked ps1 file and tried hard to make it work, and I'm embarrassed to say it took me a half hour to realize that his script only worked on prem, not in the cloud. So I spent another half hour trying to figure out the SPO versions of his commands and in the end gave up.
(I'm not a powershell guru in case you couldn't tell)
I looked at the first script but it's doing too many things with dll files that I can't figure out so I'm afraid to try to run it. It looks much more complicated than the 2nd script.
Tuesday, June 18, 2019 9:55 AM
Hi, Ted,
I tried the second script with a list of 10k items. After several hours it successfully finished deletion. Make sure you have all the Pre-requisites. Especially the SharePoint Online Management Shell and the SDK.
Best Regards
Jerry
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
SharePoint Server 2019 has been released, you can click
here to download it.
Click
here to learn new features. Visit the dedicated
forum to share, explore and talk to experts about SharePoint Server 2019.