2

We came across a scenario where we want to run a reusable workflow on all List items in a list. I am not sure if this can be achieved through PowerShell. Can any one please help me to run reusable workflows through PowerShell script on all list items?

2 Answers 2

1

Check if you are looking for something like this:

# URL of the Site
$web = Get-SPWeb -Identity "https://sharepointsrv/site1"

$manager = $web.Site.WorkFlowManager

# Name of the list
$list = $web.Lists["Shared Documents"]

# Name of the Workflow
$assoc = $list.WorkflowAssociations.GetAssociationByName("On Item Created","en-US")

$data = $assoc.AssociationData
$items = $list.Items
foreach($item in $items)
 {
 $wf = $manager.StartWorkFlow($item,$assoc,$data,$true)
 }

$manager.Dispose()
$web.Dispose()
#

Click here for details

4
  • I think it will only work for list workflows but not for Reusable workflows as it is associated to content type. i tried this as it works only on list workflows. Jul 4, 2014 at 6:29
  • Please check this link social.msdn.microsoft.com/Forums/en-US/… Jul 4, 2014 at 6:37
  • Hmm how to trigger on all Items. It only has attaching workflows to the content types. Jul 4, 2014 at 11:20
  • Can any one help me in this regards. I tried triggering normal workflows but not workflow which is associated to content type. I.e Reusable workflow Jul 14, 2014 at 16:34
1

Here is the script to run a workflow(REUSABLE) which is associated to a content type on all work items.But when we run the below script it will take 5 minutes to start the workflows.

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$url = "http://santosh-sharepointexpert.com"
$web = get-spweb $url
$list = $web.Lists["Provide List Name "]
$cTypes = $list.ContentTypes
$cType = $cTypes["Provide content type name"]
$manager = $web.Site.WorkFlowManager


foreach($wf in $cType.WorkflowAssociations)
{
   if($wf.Name -eq "Provide your reusable workflow name ")
   {
    $data = $wf.AssociationData
       #write-host $wf.Name, $wf.Id, $wf.AssociationData          
       foreach($listitem in $list.Items)
       {          
       $wfs = $manager.StartWorkFlow($listitem,$wf,$data,$true)
        #write-host $wfs.InternalState
       }
   }
   $manager.Dispose()
    $web.Dispose()
} 

Thanks, Sandy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.