In some scenario, we might need to develop workflows for existing SharePoint list which has several list items. This happens because of some enhancements or user(s) requirements. Normally, we develop workflow for list or libraries, and workflow can execute manually, item add or update automatically.

Note: workflow means SharePoint workflow which is developed via SharePoint designer.

However, in some cases, we need to run workflow all items in List which is very panic work via SharePoint GUI. We must select each list item and run workflow manually which is not effective or feasible in case of too many items in list. Additionally, it is time consuming task to run workflow for each item.

Here, I am sharing a small piece of code in PowerShell command through which we can accomplish this requirement but note this will not start instantly those workflows. However, it can take up-to 5 minutes as it is triggered through SharePoint Timer Service. (use SharePoint PowerShell)

$webApp = Get-SPWebApplication "http://sharepointUrl/sites/sitename"    
# URL of the Site    
$web = Get-SPWeb -Identity "http://sharepointUrl/sites/sitename"    
$workflowmanager = $web.Site.WorkFlowManager    
# Name of the list    
$list = $web.Lists["List Name"]    
# Name of the Workflow    
$assocname = $list.WorkflowAssociations.GetAssociationByName("On Item Created","en-US")    
$data = $assocname.AssociationData    
$items = $list.Items    
foreach($item in $items)    
 $workflow = $workflowmanager.StartWorkFlow($item,$assocname,$data,$true)    

After running this PowerShell script, the workflow will be triggered for each item in the mentioned list. This small PowerShell script saves huge time which we do manually to run the workflows.

By Rijwan Ansari

MVP, CSM, CSPO, MCP, MCTS. Sr. Software Developer. Expertise in ASP.NET MVC, Angular, AngularJs, .Net Core, C#.NET, Azure, Cognitive Services, Machine Learning, SharePoint, Azure Services, and tools, Requirement Analysis, Team Management, Pre-Sales and more. Ability to work independently and Team, handle pressure and meet commitment. Excellence Communication and adjust in any environment

Leave a Reply

Your email address will not be published. Required fields are marked *