Skip to main content
Search Again

We think these articles could help you:

    See More

    ALERT: This site will be decommissioned at the end of December 2018. All existing and new Nintex knowledge content will be available within the new Knowledge Base area of the Nintex Community site. 

    Nintex Knowledge Base

    How to terminate multiple instances of the same workflow

    Status: Pending Clean Up

    TOPIC
    How to terminate multiple instances of the same list workflow
    INSTRUCTIONS
    Copy the below PowerShell script and save as a ps1 file. Execute the ps1 file and you should be prompted to enter information retaining to the location of the workflow you want terminated. This script will terminate all instances of the list workflow by workflow name.

    ---------------------------------------------------------------------------------------------------------
    Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
    function Cancel-SPWorkflow(){
    PARAM 
    (
    [Parameter(ValueFromPipeline=$true)] [Microsoft.SharePoint.Workflow.SPWorkflow] $SPWorkflow
    )

    BEGIN {
      }

    END {
    }

    PROCESS {
            [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($SPworkflow)
        }
    }
    function Get-SPWorkflow(){
    PARAM 
    (
    [Parameter(ValueFromPipeline=$true)] [Microsoft.SharePoint.SPListItem] $SPListItem
    )

    BEGIN {
      }

    END {
    }

    PROCESS {
            $SPListItem.Workflows
        }
    }
    $siteurl = Read-Host "Enter the site URL"
    $web = Get-spweb $siteurl
    $listname = Read-Host "Enter the name of the list"
    $workflowname = Read-Host "Enter the name of the workflow"
    $targetlist = $web.Lists["$listname"]
    $WFA = $targetlist.workflowassociations | WHERE {$_.Name -eq $workflowname} 
    $WFID = $wfa.id 

    $choice = ""
     while ($choice -notmatch "[y|n]"){
         $choice = read-host " Are you sure want to cancel all workflow instances of $workflowname from $listname ? (Y/N)"
         }
     
    if ($choice -eq "y"){

    $(Get-SPWeb $siteurl).Lists[$listname].Items | Get-SPWorkflow | where {[String]$_.AssociationID -match [String] $WFID} | Cancel-SPWorkflow

    Write-host "All instances of" $workflowname "workflow have been cancelled."

    }

    else {write-host "Please correct the information."}
    ADDITIONAL INFORMATION
    RELATED LINKS
    • Was this article helpful?