Items bulk deletion


Hello everyone,

Today I will talk about the massive removal of elements in SharePoint. Several possibilities exist, but the faster is the use of a batch via PowerShell.

You can find several websites / blogs on “how to create the batch” but for those I tested, I’ve always had a little something to change.

Sample sites :

(by the way, thank you to all authors for their help in understanding the operation !)

In fact it is usually in the parameter “owsfileref” that divergent versions. Some do not specify, some  yes but other ways.

For me, here is the code that I use and that works for library documents and custom list.

Warning! Pay attention to the line


You can see that the values ​​1.0 and UTF-8 are not quoted with a simple  but with `”. I do not know why but the simple  raises an error « Exception calling « ProcessBatchData » with « 1 » argument(s) » when running the script!

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

$urlSite = “http://serverurl”

$listname = “Test”

write-host "Opening site..."

$web=get-spweb $urlSite

write-host "Opening list..."

$list=$web.lists | ? { $_.title -eq $listName}

$spQuery= New-Object Microsoft.SharePoint.SPQuery


$spQuery.RowLimit = 2000

$caml = ""




$listItems = $list.GetItems($spQuery)


$spQuery.ListItemCollectionPosition= $listItems.ListItemCollectionPosition



for($j=0;$j -lt $count; $j++)










if($i -ge $count){break}



write-host "Sending batch..."


write-host "Emptying Recycle Bin..."



while($spQuery.ListItemCollectionPosition -ne $null)


write-host "Process finished"

Hope this helps.


2 thoughts on “Items bulk deletion

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s