SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a list with about 15,000 items and I need to empty it by permanently deleting everything in the list. I have other items in the recycle bin that I don't want to disturb. Here's the script I'm running:

$url = "https://sharepoint.company.com/sites/mysite/"
$web = get-spweb $url
$list = $web.Lists["DropOffArchive"]
$listItems = $list.Items
$listItemsTotal = $listItems.Count
for ($x = $listItemsTotal-1; $x -ge 0; $x--) {
    Write-Host("$x DELETED: " + $listItems[$x].name)
    $listItems[$x].Recycle()
}

It appears this is working, but the problem is that it's taking roughly 45 seconds per item. At this rate it will take 3-4 days to fully empty the list. Doing some searching I've found that I can disable the recycle bin on the site, delete the items, they will be permanently deleted, and then turn on the recycle bin. That sounds like it will be much faster, but it will also purge everything currently in the recycle bin.

Are there any better options I'm missing?

share|improve this question
up vote 3 down vote accepted

If I am not wrong, I think $listItems[$x].Recycle() deletes the list item and puts it in the recycle bin whereas $listItems[$x].Delete() deletes the item permanently. Moreover, I think you should use Batch Delete i.e. SPWeb.ProcessBatchData() to make deletion faster. This example shows how you can do batch deletion in a list/library: http://sharepointnadeem.blogspot.in/2013/01/bulk-delete-items-in-sharepoint.html

share|improve this answer
1  
You are not wrong. Thanks! – Elijah W. Gagne Feb 3 '13 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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