Remove all workflows using PowerShell

The below script will help to delete all workflows from all sites in a single shot.

param([string]$SiteURL)
$site=Get-SPSite($SiteURL);
foreach($web in $site.AllWebs)
{
      Write-Host "Web Title: "$web.Title
      $listColl = $web.Lists;
      for($itr1=0; $itr1 -lt $listColl.Count; $itr1++)
     {
          $list = $listColl[$itr1];
          $wfColl = $list.WorkflowAssociations;
          if($wfColl.Count -gt 0)
         {
              Write-Host "List Title: "$list.Title;
         }
         for($itr2=$wfColl.Count-1; $itr2 -ge 0; $itr2--)
        {
            $wf = $wfColl[$itr2];
            $list.RemoveWorkflowAssociation($wf);
            $list.Update();
            Write-Host "Removed Workflow: "$wf.Name
        }
     }
}
$site.Dispose()

You can still find workflow templates/definitions in the designer, that is because of SharePoint stores all workflow definitions/templates in a hidden list "Workflows". By deleting items from a list, you can remove workflows completely. The above scripts just deletes all instances and workflow associations on a list.

Comments

Popular posts from this blog

Switch from Classic to Claims Authentication in SharePoint 2010

How to query list data using web service