How to Start Workflow in SharePoint 2013 Using PowerShell

 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.
 
  1. # URL of the Site  
  2. $web = Get-SPWeb -Identity "https://mysite/sites"  
  3.   
  4. #Get the Workflow Manager.  
  5. $workmanager = $web.Site.WorkFlowManager  
  6.   
  7. # Name of the list  
  8. $list = $web.Lists["Picture Library"]  
  9.   
  10. # Name of the Workflow  
  11. $assoc = $list.WorkflowAssociations.GetAssociationByName("PictureNameUpdates","en-US")  
  12.    
  13. $data = $assoc.AssociationData  
  14. $items = $list.Items  
  15. foreach($item in $items)  
  16.  {  
  17.  $wf = $workmanager.StartWorkFlow($item,$assoc,$data,$true)  
  18.  }  
  19.     
  20. $workmanager.Dispose()  
  21. $web.Dispose()  
 
Happy SharePointing :-)
 
Feel free to add if you have any points around it!! 
 
Ebook Download
View all
Learn
View all