Cancelling Workflows in a SharePoint List

If you had asked to cancel all the workflows associated to a SharePoint List, you don't need to go to UI interface and do Remove Workflows .Here are the list of power shell commands given below.
 
$web = Get-SPWeb "http://mysite/testsite";
$web.AllowUnsafeUpdates = $true;

#List Name
$list = $web.Lists["Customers"];

# Iterate through all Items in List and all Workflows on Items.
 
foreach ($item in $list.Items) {
foreach ($wf in $item.Workflows) {

#Cancel Workflows
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf);
}
}
$web.Dispose();

*Customers is the list Name where are removing all the workflows associated to it.
Ebook Download
View all
Learn
View all