How to cancel all workflows from one List in SharePoint using PowerShell?

sharepoint cancel all workflows on a list

Tags: SharePoint cancel workflows in progress, cancel all workflows on a list, cancel all workflows on a list SharePoint 2013, cancel all workflows SharePoint 2013, cancel all workflows SharePoint 2013 using PowerShell


New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

This SharePoint workflow tutorial explains, how to cancel all workflows from one list in SharePoint using PowerShell. It will cancel all list workflows as well as site workflows from the list.

We have tested this PowerShell script in our environment, Hope it will work for you.

PowerShell: Terminate a workflow for all items in a list on SharePoint

#Site URL
$web = Get-SPWeb “http://urlforsite.com”;
$web.AllowUnsafeUpdates = $true;

#List Name
$list = $web.Lists[“ListName”];

# 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();

PowerShell:

$site = Get-SPSite “<your url>”;
$site.AllWebs | foreach {
$web = $_;
$web.AllowUnsafeUpdates = $true;

# stop list workflows
$web.Lists | foreach {
$list = $_;
$list.Items | foreach {
$item = $_;
$item.Workflows | foreach {
$wf = $_;
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf);
}
}
}

# stop site workflows

$web.Workflows | foreach {
$wf = $_;
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf);
}
$web.AllowUnsafeUpdates = $false;
$web.Dispose();
}


$site.Dispose();

You may like following SharePoint designer workflow tutorials:

Hope this will be helpful to cancel all workflows from a SharePoint list using PowerShell in SharePoint 2013.

Check out Best Alternative to InfoPath -> Try Now

FREE SHAREPOINT 2019 PDF

(Installation & Features)