4

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?

1 Answer 1

5

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

1
  • 1
    If I delete using Batch Delete, all items goes to Recycle bin. How should I delete list Item permanently?
    – salah9
    Commented Aug 9, 2017 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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