25th March 2014 Update: Script and download have been update.  Typo preventing the script working has been fixed.

Within SharePoint 2010, Workflow can be designed from two perspectives: -

  1. At Administrator / Power User Level via SharePoint Designer
  2. At Developer level via Visual Studio

SharePoint Designer workflows aren't compiled and distributed via the WSP Infrastructure.  Instead they are simply edited, checked and published via the Designer Interface.


What this results in, is many previous vesions of Designer Workflows being copied left within the lists / libraries or sites that they are attached too.

The intention of this script is to provide a SharePoint Administrator with the utility to remove previous versions of thier SharePoint Designer Workflows.


To use the script

Doiwnload and edit the script with the following variables: -

  1. $web: Include the URL of your Site
  2. $listToCancel: Use the display name of the list / library that has the workflow versions you want to delete
  3. $wfToKeep: Use the name of the workflow to be pruned



Add-PSSnapin Microsoft.SharePoint.PowerShell  
#Set the $ErrorActionPreference to "STOP" so that the script stops if there are any errors  
$ErrorActionPreference = "STOP"  
#Declare the Variables 
$web = Get-SPWeb "http://sp2010" 
$listToCancel = "CodePlex Links" 
$list = $web.Lists[$listToCancel] 
$tempList = New-Object "System.Collections.Generic.List``1[System.Object]" 
#Workflow Name.  check against the Workflow Status Column 
$wfToKeep = "Demonstration Workflow" 
foreach ($wf in $list.WorkFlowAssociations) { 
if ($wf.Name -ne $wfToKeep) { $tempList.Add($wf); } 
foreach ($wf in $tempList){ $list.RemoveWorkflowAssociation($wf); }