aaron.labiosa@nintex.com

How to bulk cancel list item workflows with a status of "Error Occurred"

Blog Post created by aaron.labiosa@nintex.com Champion on Oct 20, 2014

Products: Nintex Workflow 2013

 

 

A common request we see is "How do I cancel/terminate a group of list item workflows that are in a state of 'Error Occurred'?" This article provides instructions on how to accomplish this.

 

 

Run the below (attached as well as a *.txt file for your convenience) PowerShell script (PowerShell ISE works well) from a SharePoint Server:

 

 

PowerShell Script

 

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
    }

}

$(Get-SPWeb http://contoso.com).Lists["DocumentLibrary"].Items | Get-SPWorkflow | where {[String]$_.StatusText -match [String]"Error"} | Cancel-SPWorkflow

 

To use the script, replace http://contoso.com and DocumentLibrary with the URL of the site and list title you wish to execute the script against.

 

For the Site Workflow version of this article go here: How to bulk cancel site workflows with a status of "Error Occurred"

Attachments

Outcomes