Easiest way of cancelling all SharePoint Workflows in Progress

By | November 7, 2013

Do you have a really big list in SharePoint and has a workflow attached to it? Had you encountered an issue where this workflow suddenly stopped and left a good number of Workflows in progress?

Workflow Settings

Have you ever wondered where do you find these workflows in progress? going to each list one by one will be OK if you have 10 items on your SharePoint List but if you have 1000 that can be a daunting task cancelling them all by going to each list item.  Well things can be easier by using SharePoint Powershell where you can iterate to all list items that has workflows attached to them and cancel them programatically if  they confirm to a certain condition, like when they are not “Completed” or “Suspended”.

I had the same issue last week and I have to stop all of them and this is how did it in Powershell

#Your Shaeproint Site URL
$web = Get-SPWeb "http://yoursharepointserver.com/yoursubsite";
$web.AllowUnsafeUpdates = $true;    

#Your List Name
$list = $web.Lists["YourListName"];
$count = 0

#Loop through all Items in List then loop through all Workflows on each List Items.         
foreach ($listItem in $list.Items) 
	foreach ($workflow in $listItem.Workflows) 
		#Disregard Completed Workflows 
		if(($listItem.Workflows | where {$_.InternalState -ne "Completed"}) -ne $null)
			#Cancel Workflows        
			write-output "Workflow cancelled for : " $listItem.Title;  

You can also change the condition based on what your requirements are for a full list of what’s available please check it here.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.