I am in the process of developing a workflow for my company, and I have noticed that my workflows are not terminating properly. If you go to the workflow settings for a list, it will show a very high amount of active workflows yet there isn't that many.

My current workflow shows 165 workflows in progress, but when I run this script, it only shows 16 active workflows:

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$web = get-spweb -Identity ************
$list = $web.Lists["**List in Question**"]

$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$sub = $wfm.GetWorkflowSubscriptionService()
$wf = $sub.EnumerateSubscriptionsByList($list.ID)


foreach ($item in $list.Items)

    foreach($wf in $workflowInstances) 
        $wfName = $wf | ?{$_.Id -eq $wf.WorkflowSubscriptionId} | select -ExpandProperty Name
        $wfID= $wf.Properties.'Microsoft.SharePoint.ActivationProperties.CurrentItemUrl'
        $wfStatus = $wf.Status
        $wfListItem = $item.Name
        $wfListItemID = $item.ID

        write-host "Workflow URL: " -ForegroundColor Green -NoNewline
        write-host $wfID -NoNewline
        write-host " Status: " -ForegroundColor Green -NoNewline
        write-host $wfStatus -NoNewline
        write-host " ListItem: " -ForegroundColor Green -NoNewline
        write-host $wfListItem -NoNewline
        write-host " ListItem ID " -ForegroundColor Green -NoNewline
        write-host $wfListITemID

Most of these workflows were from items that were deleted. Can anyone advise on why deleting an item isn't properly terminating the workflows?

1 Answer 1


Check if this helps you


Basically, you need to check the status and cancel it:

 if($workflow.InternalState -ne 'Completed' -and $workflow.InternalState -ne 'Cancelled')

Hope this gives you some idea!

  • I just tried this and it didn't seem to work. This is ran based off of the the the workflows on list items, but according to my PowerShell there are no items in the list.
    – Rbenjamin
    May 19, 2017 at 12:24
  • The code posted by @user2598808 is intended for WF2010. You are using WorkflowServicesManager which manages 2013WFs.
    – Emaborsa
    May 16, 2018 at 14:44

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.