SP: Purging document libraries with Powershell

I wanted to purge the contents of a huge document library. Because of the 5000 item limit, using the GUI or explorer view wasn’t posssible any more. There are a couple of scripts out there which can help, based on the ProcessBatchData method to process batches of operations at once. This is often the best scenario, because deleting items one by one takes a lot of time.

Now upon deletion, you can get all kinds of non descriptive errors (operation failed, 0xblabla…). When your script fails after some items were deleted, there is a good chance check-outs are in the way of deletions. Checked-out files have to be checked-in again before they can be deleted, and folders to be deleted cannot contain any checked-out items either. So I create a purge script which takes care of all of these kinds of things, before deleting the entire contents of a library. I’m saving it here mainly for my own reference, but feel free to use it when you want to!

2 thoughts on “SP: Purging document libraries with Powershell

Leave a Reply

Your email address will not be published. Required fields are marked *