Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 2 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
    
You are not wrong. Thanks! –  Elijah W. Gagne Feb 3 '13 at 15:17
add comment

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.