How to list all Workflow Items that have not completed Succussfully

If have tons of Workflows running. But form time to time I have a number of WorkFlows running that did not complete successfully.

In order to investigate the which items it concerns I have this little PowerShell Script.

Once you know the Item ID you can go there and cancel the workflow process.

CLS

$web=get-spweb "http://www.yoursite.com/"

$list = $web.Lists["YourListName"]

write-host "# Records : " $list.ItemCount

$i = 0

foreach($wf in $list.WorkflowAssociations)
{

   if($wf.Name -eq "YourListName")
   {
       write-host $wf.Name " - " $wf.Id
       write-host ""

       foreach($listitem in $list.Items)
       {

          foreach($Workflow in $listitem.Workflows)
          {
            if($Workflow.InternalState -ne "Completed")
            {
             # if($Workflow.AssociationId -eq $wf.ParentAssociationId) # change to if needed
             # {
                 write-host $i $Workflow.AssociationId " - " $Workflow.InternalState  " - "  $listitem.ID $listitem.Title $listitem.Title
                 $i++
             # }
            }

          }
       }
   }
}

Later on I hope to create a Cancel WF PowerShell script. Well here it is

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: