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

Here will discuss how we can discuss how we can cancel all workflows from one list in SharePoint using PowerShell. It will cancel all list workflows as well as site workflows from the list.

Also, read some Microsoft Azure tutorials

We have tested this PowerShell script in our envirment, 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();


Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials: