Monday, August 22, 2016

Start/Update Workflow for existing items in SharePoint List using PowerShell

The following script is useful to start/update workflow for existing items in SharePoint list.

#updated workflow

# URL of the Site
$web = Get-SPWeb -Identity "<<Site URL>>"

$manager = $web.Site.WorkFlowManager

# Name of the list
$list = $web.Lists["<< List Name>>"]

# Name of the Workflow
$assoc = $list.WorkflowAssociations.GetAssociationByName("<< 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()
#