Cancel multiple SharePoint Workflows using PowerShell
Give this one a shot.
I modified it so that it is done on a specific list on a specific web.
#Site URL$web = Get-SPWeb "http://urlforsite.com";$web.AllowUnsafeUpdates = $true; #List Name$list = $web.Lists["ListName"];# Iterate through all Items in List and all Workflows on Items. foreach ($item in $list.Items) {foreach ($wf in $item.Workflows) {#Cancel Workflows [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf); }}$web.Dispose();
Worked just fine for me. Let me know if it works for you.
This script has been wickedly useful to me. I make a modification to allow me to cancel all the workflows in one list or just one workflow and thought I would post it here too:
#Parameters param($listToCancel,$WfToCancel) #Site URL $web = Get-SPWeb "http://mydomain.com"; $web.AllowUnsafeUpdates = $true; #List Name $list = $web.Lists[$listToCancel]; #Add wildcards to Wf variable $WildcardWfToCancel = "*"+$WfToCancel+"*"; # Iterate through all Items in List and all Workflows on Items. foreach ($item in $list.Items) { foreach ($wf in $item.Workflows) { #Test for workflow complete and match criteria if (($wf.ParentAssociation.InternalName -like $WildcardWfToCancel) -and ($wf.IsCompleted -ne $true)) { #Show status and cancel Workflows write-Host $wf.ItemName -nonewline; write-host " " -nonewline; write-host $wf.ParentAssociation.InternalName; Write-Host " Status " -nonewline; Write-host $wf.InternalState; [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf); } } } $web.Dispose();
Try this (simple "translation" of C# to powershell):
$site = Get-SPSite "<your url>";$site.AllWebs | foreach { $web = $_; $web.AllowUnsafeUpdates = $true; # stop list workflows $web.Lists | foreach { $list = $_; $list.Items | foreach { $item = $_; $item.Workflows | foreach { $wf = $_; [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf); } } } # stop site workflows $web.Workflows | foreach { $wf = $_; [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf); } $web.AllowUnsafeUpdates = $false; $web.Dispose();}$site.Dispose();