0

I am trying to delete list items, about 130K, from a large list on SharePoint Online using powershell CSOM, i am getting this error

"Exception calling "ExecuteQuery" with "0" argument(s): "The operation has timed out.""

this is my code

    for ($i=$allItems.Count-1; $i-ge0; $i--)  
    {  
        $allItems[$i].DeleteObject()
        #$clientContext.ExecuteQuery()   
    }   
    $clientContext.ExecuteQuery() 

When i use the ExecuteQuery() outside the loop, i am getting this error. but it still deletes around 1K items each time i run the script.

But When i use the ExecuteQuery() inside the loop, it doesn't throw the error and the script completes execution, BUT it takes about 20 times the time taken to delete items when ExecuteQuery() used outside the loop

i also used RequestTimeout property

$clientContext.RequestTimeout = [System.Threading.Timeout]::Infinite ( or any value)

it doesn't seem to honor this property.

Could anyone please help me suggest a better way to delete such a large list ( the list is still being used, i can't delete the list)?

Thanks so much Maria Francis

  • 2
    Try to delete items in batches of 100 items. Looks like you are reaching the CSOM batching limits – Gautam Sheth May 2 '18 at 17:26
  • it works fine for a batch of 100 items and it is fast too.. thanks – Maria Francis May 2 '18 at 19:08
  • Look at this example sharepointdiary.com/2016/12/… – Fox May 3 '18 at 7:13
  • i used this one sptrenches.com/2016/06/… – Maria Francis May 3 '18 at 16:37
  • my problem was deleting all items. Now i deleted 100 items a batch. it took about 6 hours to complete. All is well now – Maria Francis May 3 '18 at 16:38
0

i changed the code as given below and it worked perfect. hope this helps someone

Thanks Team

if ($allItems.Count-gt0)  
{  
$counter = $allItems.Count    
While ($counter-gt1 )
{
$g = 0
    for ($i=$counter-1; $i-ge0-and $g-lt100; $i--)  
    {  
        $allItems[$i].DeleteObject()         
        $g = $g+1            
    }   
    $clientContext.ExecuteQuery() 
    $counter = $counter - 100
 } 

}  

To get all items, i followed this

https://www.sptrenches.com/2016/06/get-all-items-in-5000-large-list-with.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.