1

I can't find anything on Google about this and I've been searching for a while. I'm trying to call a SharePoint 2013 List Workflow on each item within a given list.

Add-PSSnapin microsoft.sharepoint.powershell
$sourceWebURL = '[redacted]'
$sourceListName = 'Skilled Persons'
$TargetWorkflow = 'Appointment'
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]

$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spSourceweb)

$sub = $wfm.GetWorkflowSubscriptionService();

$WF = $sub.EnumerateSubscriptionsByList($spSourcelist.ID) | Where-Object {$_.Name -eq "$TargetWorkflow"}

$wfis = $wfm.GetWorkflowInstanceService()

foreach ($item in $spSourceList.Items) {
    $object = New-Object 'system.collections.generic.dictionary[string,object]' 
    $object.Add("WorkflowStart", "StartWorkflow");
    $wfis.StartWorkflowOnListItem($WF, $item.ID, $object);
}

This almost identically matches the version here:

$sourceWebURL = '<URL>'
$sourceListName = '<List Name>'
$TargetWorkflow = '<Workflow Name>'
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]

#-- Getting a Workflow manager object to work with.
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spSourceweb)
#-- Getting the subscriptions
$sub = $wfm.GetWorkflowSubscriptionService()
#-- Getting the specific workflow within the list of subscriptions on the specific list. (SP2010 associated workflows basically)
$WF = $sub.EnumerateSubscriptionsByList($spSourcelist.ID) | Where-Object {$_.Name -eq "$TargetWorkflow"}
#-- Getting a Workflow instance in order to perform my commands.
$wfis = $wfm.GetWorkflowInstanceService()

Foreach($item in $spSourceList){
    #-- Creating the dictionary object I need to parse into StartWorkflow. This could be most other workflow commands.
    $object = New-Object 'system.collections.generic.dictionary[string,object]'
    $object.Add("WorkflowStart", "StartWorkflow");
    $wfis.StartWorkflowOnListItem($WF, $item.ID, $object)
}

I have checked that $WF, $item.ID and $object are all the correct type and see no reason that this should not work. Any help would be greatly appreciated.

1
  • i have the same problem! did you get the solution please?
    – Jihen
    Feb 1, 2019 at 9:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.