Let's take a simple scenario where you want to run workflow on each and every single item in a document library. The immediate option that comes to everyone's mind is using User Interface through Ribbon in List Item menu. The main disadvantage of this process is that it is time consuming one. You need to manually go to the each list item and trigger the workflow and wait for its completion .
The best and time saving way is to run through the Powershell commands. In this blog , I will share the piece of code that can do the job for you.
- # URL of the Site
- $web = Get-SPWeb -Identity "https://mysite/sites"
- #Get the Workflow Manager.
- $workmanager = $web.Site.WorkFlowManager
- # Name of the list
- $list = $web.Lists["Picture Library"]
- # Name of the Workflow
- $assoc = $list.WorkflowAssociations.GetAssociationByName("PictureNameUpdates","en-US")
- $data = $assoc.AssociationData
- $items = $list.Items
- foreach($item in $items)
- {
- $wf = $workmanager.StartWorkFlow($item,$assoc,$data,$true)
- }
- $workmanager.Dispose()
- $web.Dispose()
Happy SharePointing :-)
Feel free to add if you have any points around it!!

Himanshu SaxenaPosted May 2, 2019, 7:13 PM
$list.WorkflowAssociations will give you list of 2010 workflows not 2013 workflow.. how you are planning to associate WFM and 2010 workflow?