Click here to Skip to main content
Click here to Skip to main content

Tagged as

Easiest Way of Cancelling All SharePoint Workflows in Progress

, 7 Nov 2013
Rate this:
Please Sign up or sign in to vote.
The easiest way to cancel all SharePoint workflows in progress

Do you have a really big list in SharePoint and have 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 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 have workflows attached to them and cancel them programmatically if they confirm to a certain condition, like when they are not “Completed” or “Suspended”.

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

#Your SharePoint 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        
			[Microsoft.SharePoint.Workflow.SPWorkflowManager]::
					CancelWorkflow($workflow);      
			write-output "Workflow cancelled for : 
					" $listItem.Title;  
		}
	}
}
$web.Dispose();

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

Filed under: CodeProject, Programming, Tips
Tagged: Powershell, Sharepoint 2013, Sharepoint Foundation 2013

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Raymund Macaalay
Technical Lead
New Zealand New Zealand
http://nz.linkedin.com/in/macaalay
http://macaalay.com/
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
QuestionBetter options - script Pinmember322222221-Apr-14 0:15 
SuggestionA more efficient variation PinmemberPaul Ryan6-Jan-14 0:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 7 Nov 2013
Article Copyright 2013 by Raymund Macaalay
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid