0

I have many running workflows in our SharePoint 2016 environment where I have seen - if we go to the workflow settings page from the library settings, there we could see multiple instances of running workflow, however, if I go to the SharePoint library and filter on workflow name column, we don't see any running workflow, only we could see completed or error out workflow status. Then wherefrom these running instances have been shown on the workflow setting page? Below is one of the examples.

Running Workflow Issue

By the way, these workflows have been migrated from SharePoint 2010 -> SharePoint 2013 -> SharePoint 2016

Any thought? We want to clean up these running instances.

1 Answer 1

1

1.PowerShell to terminate 2010 workflow.

$web = Get-SPWeb "site collection URL"

$list = $web.Lists["list name"]

$WorkFlowToCancel = "the workflow name"

foreach ($item in $list.Items)
{
foreach ($wf in $item.Workflows)
 {
    #Check for the particular workflow
    if($wf.ParentAssociation.Name -eq $WorkFlowToCancel)
    {  
        #Cancel Workflow
        [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf)                 
    }
 }
}

2.PowerShell to terminate 2013 workflow.

$siteURL = "site collection URL"
$listName = "list name"
 
$spWeb = Get-SPWeb $siteURL
$spList = $spWeb.Lists[$listName]
$spListItems = $spList.Items
 
$wfMgr = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spWeb)
$wfInstanceSvc = $wfMgr.GetWorkflowInstanceService()
 
foreach($spListItem in $spListItems)
{  
    $wfInstances = $wfInstanceSvc.EnumerateInstancesForListItem($spList.ID, $spListItem.ID)
    
    foreach($wfInstance in $wfInstances)
    {
       write-host("Terminating instances for list item: {0}" -f $spListItem.ID)     
       $wfInstanceSvc.TerminateWorkflow($wfInstance)
        
    }
}
2
  • Thanks for the reply, could you please little elaborate on why we are not seeing those running instances when filter the workflow column in the view - actually wondering to know the technical cause.
    – SP 2022
    Commented Dec 10, 2020 at 10:40
  • I think it is caused by migrated workflows. Commented Dec 11, 2020 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.