How to start a SharePoint 2013 Workflow on all list items via PowerShell

Unfortunately you can not use the same commands to start a SharePoint 2013 Workflow that you use to start a SharePoint 2010 Workflow via PowerShell.
Here’s what you’ve got to do:

$web = Get-SPWeb -Identity ""
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$list = $web.Lists["My List"]
$items = $list.Items
$sub = $wfm.GetWorkflowSubscriptionService()

$wfis = $wfm.GetWorkflowInstanceService()
$subscriptions = $sub.EnumerateSubscriptionsByList($list.ID)
$subscription = $subscriptions | Where-Object {$_.Name -eq 'IdeaCreated'}

#Optional step to filter list items (This example only selects the document sets, not the files)
$items=$items | Where-Object {$_.Folder -ne $null}

foreach($item in $items)
$object = New-Object 'system.collections.generic.dictionary[string,object]'
$wfis.StartWorkflowOnListItem($subscription, $item.ID, $object)

Leave a Reply

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