Start a Workflow for Multiple Items

Post date: Dec 02, 2013 7:19:54 PM

Ever have the need to start a List Workflow for multiple list items? For example, you have an existing list with 1,000 items and you have now created a new workflow; now you need to run that workflow on all 1,000 items. This is painful to do one-by-one, but is there a better way? There sure is...let's initiate the Workflow using PowerShell.

The following code can be used in PowerShell to initialize the Workflow through the SharePoint Timer Service. Since it is being invoked by the Timer Service, it may take a few minutes for the Workflows to actually initialize.

# URL of the Site

$web = Get-SPWeb -Identity "http://mysharepoint/site"

$manager = $web.Site.WorkFlowManager

# Name of the list

$list = $web.Lists["My List Name"]

# Name of the Workflow

$assoc = $list.WorkflowAssociations.GetAssociationByName("My Workflow Name","en-US")

$data = $assoc.AssociationData

$items = $list.Items

foreach($item in $items)

{

$wf = $manager.StartWorkFlow($item,$assoc,$data,$true)

}

$manager.Dispose()

$web.Dispose()