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

InfoPath alternatives for form designing SharePoint

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 you can read:
– SharePoint 2016 workflow manager error Service FabricHostSvc was not found on Computer

– How to delete list items in SharePoint Online using Client Side Object Model with PowerShell?

– Bulk Export SharePoint Files using PowerShell

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.

Similar SharePoint 2013 Tutorials


Leave a Reply