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

Research and Technology Lead | Software Architect | Full Stack .NET Expert | Tech Blogger | Community Speaker | Trainer | YouTuber. Follow me @ Md Rijwan Ansari is a high performing and technology consultant with 10 plus years of Software Development and Business Applications implementation using .NET Technologies, SharePoint, Power Platform, Data, AI, Azure and cognitive services. He is also a Microsoft Certified Trainer, C# Corner MVP, Microsoft Certified Data Analyst Associate, Microsoft Certified Azure Data Scientist Associate, CSM, CSPO, MCTS, MCP, with 15+ Microsoft Certifications. He is a research and technology lead in Tech One Global as well as leading Facebook community Cloud Experts Group and SharePoint User Group Nepal. He is a active contributor and speaker in community, C# Corner MVP and his rank at 20 among 3+ millions members. Additionally, he is knee to learn new technologies, write articles, love to contribute to the open-source community. Visit his blog RIJSAT.COM for extensive articles, courses, news, videos and issues resolution specially for developer and data engineer.

Leave a Reply

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