Rather terminating the errored workflows, I would suggest to find the root cause for erroring the workflows. Issue could be with workflow logic, or Nintex Services or Nintex related timer jobs.
Here is a script to terminate all workflows on task items with a due date of more than 7 days in the future.
#Get Site COllection
$siteCollection = Get-SPSite "http://sharepoint.dev.com/sites/site/"
#Your Shaeproint Site URL
$spWeb = Get-SPWeb "http://sharepoint.dev.com/sites/site/sub-site";
$spWeb.AllowUnsafeUpdates = $true;
$WFManager=$Web.site.WorkFlowManager
$deadline = (get-date).AddDays(7)
foreach($subSite in $spWeb.Webs)
{
$subSite.Title
$subSite.AllowUnsafeUpdates = $true
$WFManager=$subSite.site.WorkFlowManager
$list = $subSite.Lists["Requirements"]
foreach ($listItem in $list.Items)
{
$duedate = [datetime]$listItem["Due Date"]
if ($duedate -gt $deadline)
{
foreach ($workflow in $listItem.Workflows)
{
# Write-Host "internal State: " $workflow.InternalState
if ($workflow.InternalState -ne "Completed")
{
# Cancel Workflow
[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($workflow);
# start workflow
$WFAssociation = $list.WorkFlowAssociations | where {$_.Name -Like "*Requirement Reminders"}
Write-Host "wf association $WFAssociation"
$WFManager.StartWorkFlow($item,$WFAssociation,$WFAssociation.AssociationData)
}
}
}
}
$subSite.Dispose()
}
$spWeb.Dispose()
Hi,
that's not that easy: we also have users which have no programming skills who also build worklfows or are allowd to bulid them. Unfortunately, those WFs often have some design flaws or they don't test the WF well and so errors occure once in a while. The WFs designed by the IT department run like a charm - so its not timer related.
BR, Alex