Have you ever been in a situation where you have had a lot of workflows that has been started and ended up in a Error Occurred state? Where you tired of terminating them one by one before you could start the workflow again? Well I was, so I wrote a small and simple PowerShellScript for it.
What the script does is that you specify a site, list and workflow name and then all workflows will be terminated so that you can run them again. I also included the option to include already running Workflows and also a Restart parameter that could actually be used to start multiple Workflows only.
This is how it looks:
DESCRIPTION:
NAME: Cancel-SPWorkflow
Cancel SharePoint Workflows and restart them if wanted
| PARAMETERS: | |
| -Site | Url to the SharePoint Site |
| -List | Name of the list |
| -Workflowname | Name of the workflow |
| -Restart | Optional if you want to restart the workflows |
| -IncludeRunning | Optional if you want to include running workflows |
| -help | Displays the help topic |
SYNTAX:
Cancel-SPWorkflow -help
Displays the help topic for the script
Cancel-SPWorkflow -site http://yourSPSite -list Listname -Workflowname YourWorkflow
Terminates all workflows with the specific workflow name
Cancel-SPWorkflow -site http://yourSPSite -list Listname -Workflowname YourWorkflow -Includerunning
Terminates all workflows with the specific workflow name and include running workflows
Cancel-SPWorkflow -site http://yourSPSite -list Listname -Workflowname YourWorkflow -restart
Terminates all workflows with the specific workflow name and then restart the workflow for all items
The key in the script is how we cancel the workflow. That is done through the SPWorkflowManager and done like.
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($Workflow)
And when we want to start a workflow we first need the workflow association and association data together with the SharePoint item to start it for.
$SPList.Parentweb.site.workflowmanager.startworkflow($item, $WFAssociation, $WFAssociation.AssociationData)
You find the whole script here or from the Downloads section
Hope you find it useful









When I ran this without the -restart option, it restarted all of my workflows anyway. Not only that, but it appeared to start workflows on tasks that weren’t currently started. Here’s the command I ran:
Cancel-SPWorkflow -site [my site] -list “[my list']” -Workflowname “[my wf name]” -Includerunning
Did I do something wrong? Or is this the way it’s supposed to work and I just misunderstood what it’s supposed to do?