1

I have a workflow in list and i have changed something in workflow. List has already 2000 items, new modified workflow works for new item added. can someone provide me powershell command to re-run workflow on each existing items in list. As it will be very hectic to run manually for each item. Thanks

2 Answers 2

2

Try following

# URL of Site
$web = Get-SPWeb -Identity "https://yoursite/sitetest"

$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()
#

More detail: http://www.thesysadminhimself.com/2013/09/sharepoint-start-workflow-all-items-powershell.html

2
  • 1
    Script gives an error "Exception calling "StartWorkflow" with "4" argument(s): "Value cannot be null."
    – Nina G
    Commented Sep 25, 2016 at 1:34
  • @Aspire27 Are you using SharePoint 2010 or 2013 workflow? $list.WorkflowAssociations in this answer will return only SharePoint 2010 workflows associated with that list. Commented Oct 6, 2016 at 15:43
0

I was able to do so using the script below:

$sourceWebURL = '<URL>'
$sourceListName = '<List Name>'
$TargetWorkflow = '<Workflow Name>'
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$items = $spSourceList.getItems()

#-- Getting a Workflow manager object to work with.
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spSourceweb)
#-- Getting the subscriptions
$sub = $wfm.GetWorkflowSubscriptionService()
#-- Getting the specific workflow within the list of subscriptions on the specific list. (SP2010 associated workflows basically)
$WF = $sub.EnumerateSubscriptionsByList($spSourcelist.ID) | Where-Object {$_.Name -eq "$TargetWorkflow"}
#-- Getting a Workflow instance in order to perform my commands.
$wfis=$wfm.GetWorkflowInstanceService()

Foreach($item in $items){
    #-- Creating the dictionary object I need to parse into StartWorkflow. This could be most other workflow commands.
    $object = New-Object 'system.collections.generic.dictionary[string,object]'
    $object.Add("WorkflowStart", "StartWorkflow");
    $wfis.StartWorkflowOnListItem($WF, $item.ID, $object)
}

Reference is below:

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.