Showing results for 
Search instead for 
Did you mean: 

Safely purge items from history list - PowerShell

This PowerShell script allows you to safely target and purge items from a workflow history list to keep the size down and manageable.

AuthorAaron Labiosa
Long DescriptionIn order to get rid of the items and not impact the entire farm, it becomes necessary to utilize paging and indexing to specifically target each item and delete it. Paging helps throttle the traffic to your SQL server down by only deleting x number of items at a time before it rests and starts again. Indexing enables the targeting of items without the performance overhead of enumerating and/or querying a large collection of items.

To use the script do the following:

  • Replace with the URL of the site you wish to execute the script against.
  • Replace NintexWorkflowHistory with the title of the history list you wish to target.

Note: By default the script will delete 1000 items and then rest for 1 second.

Support InfoAaron Labiosa​ - How to purge items from a large history list safely via PowerShell

Nintex Workflow 2010

Nintex Workflow 2013


SharePoint Server 2010

SharePoint Server 2013


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configure target site and list.

$list = $($(Get-SPWeb -Identity '').Lists['NintexWorkflowHistory'])

#Index count for list items.

$index = $list.ItemCount

#Index counter for paging.

$page = 0

#Configure how many items to delete per batch.

$pagesize = 1000

#Configure how may seconds to pause between batches.

$sleep = 1

#Turn verbose output on/off

$verbose = $true

While($index -ge 0){


$("Deleting item at index $($index).")


if($page -lt $pagesize){


if($($list.Items[$index])['Modified'] -lt [DateTime]::Parse("01/01/2014")){


write-host "Found Item"



catch [System.Exception]{


$("Skipping item at index $($index).")








$("Sleeping for $($sleep) seconds.")


[System.Threading.Thread]::Sleep($sleep * 1000)

$page = 0



Additional Information

Filtering can be added by adding an if statement around the Delete() call as shown below. In this example, the item would be deleted if it was older than 01/01/1999.


if((($list.Items[$index])[($list.Items[$index].Fields['Created'])] -lt [DateTime]::Parse("01/01/1999")))




Nintex Xchange Terms of Use Policy

Nintex makes no warranty or guarantee about the reliability, performance, quality, or functionality of any assets, and any assets you install are therefore provided as is. By downloading this asset, you agree to the terms of use.

Version history
Revision #:
1 of 1
Last update:
‎03-30-2016 11:17 AM
Updated by: