SharePoint – How to Cancel a Workflow that has not completed Successfully

Continuing on this List WF that have not been completed Successfully

Well here is the script to Cancel Workflows that have not been completed.


$web = Get-SPWeb ""
$web.AllowUnsafeUpdates = $true;    

#Your List Name
$list = $web.Lists["YourListName"]
$count = 0

#Loop through all Items in List then loop through all Workflows on each List Items.         
foreach ($listItem in $list.Items) 
    foreach ($workflow in $listItem.Workflows) 
        #Disregard Completed Workflows 
        if($Workflow.InternalState -ne "Completed" -and  $Workflow.InternalState -notlike "Cancelled*")
            # Cancel Workflows        
            Write-Host "Workflow cancelled for : " $Workflow.AssociationId " - " $Workflow.InternalState  " - "  $listitem.ID $listitem.Title $listitem.Title  
$web.AllowUnsafeUpdates = $false

Enjoy !


Leave a Reply

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

You are commenting using your 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: