How to Start a SharePoint Workflow using PowerShell?

Requirement is: To start a specific Workflow on All documents in a document library.

Solution: let’s use PowerShell to Start workflow Programmatically on all Items in a Document Library! After making sure, “Manual start” is enabled for the workflow.

PowerShell script to start SharePoint workflow

# For MOSS 2007 compatibility
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Region MOSS2007-CmdLets
Function global:Get-SPSite()
{
  Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )

   if($SiteCollURL -ne '')
    {
    return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
   }
}
 
Function global:Get-SPWeb()
{
 Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
  $site = Get-SPSite($SiteURL)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();
            }
    return $web
}
#EndRegion

#Get the Web
$web = Get-SPWeb "http://sharepoint.company.com"

#Get the List
$list=$web.Lists["Review Documents"]

#Get Workflow Manager
$WFManager=$Web.site.WorkFlowManager

#Get the specifi workflow, Associated with the list
$WFAssociation = $list.WorkFlowAssociations | where {$_.Name -eq "Approval Workflow"}

#Start Workflow on Each List Item
foreach ($item in $list.Items)
{
    $WFManager.StartWorkFlow($item,$WFAssociation,$WFAssociation.AssociationData)
    write-host "Started Workflow on $($item.Name)"
}
$web.Dispose()
Using this method, We can Start/Stop/Cancel even Nintex Workflows!

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

3 thoughts on “How to Start a SharePoint Workflow using PowerShell?

  • March 27, 2017 at 10:59 PM

    Does this work on SharePoint 2013

    Reply
  • October 28, 2014 at 10:29 PM

    Exception calling “StartWofkflow” with “3” argument(s): “Unable to synchronously deliver start event via a manual start workflow.: $$WFManager.StartWorkflow($item……

    Reply
    • October 29, 2014 at 7:56 AM

      Try adding the user who runs this code with “FULL Control” access rights to the site!

      Reply

Leave a Reply