Delete items in batch from SharePoint list with PowerShell script

At Mavention we have a customer with a public facing website at SharePoint 2013 that uses our query suggestions solution for the search box. So, every unique query that visitors search for is added to the query suggestions list. If visitors use a query word or sentence more than once the query count number is increased. All unique queries have to be approved by administrators so they can be used at the website.

But…during 1.5 years they did not once do some administration on this list so it had grown and grown and grown to approximately 140k items. Now they want to delete all items from the list where the “query count” is less than 5. This is approximately 80% of all items.

Well, that is a hell of a job to delete manually. I tried it. But you can only delete 100 item per delete action. So I searched for some batch processing PS script and finally my colleague Waldek Mastykarz (visit his blog) came up with some urls where I could find some info. I used the script from this site: http://matthewyarlett.blogspot.nl/2013/07/well-that-was-fun-bulk-deleting-items.html

The script below contains a query to select all items where the Query Count is < 5. Run it in these 3 stages:

Create the query:

Build the command:
Output:
output

Run the query:

After running the query the list only contained all query suggestions with a query count of 5 and more.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">