如何从PowerShell启动工作流2013

问题描述:

关于how to work with 2010 workflows using powershell有一些指南。有人能告诉我如何在2013年的工作流程中做同样的事情吗?他们不再列在$list.WorkFlowAssociations之内。如何从PowerShell启动工作流2013

$siteURL = "URL" 
$web = Get-SPWeb $siteURL 
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web) 
$sub = $wfm.GetWorkflowSubscriptionService() 
$subscriptions = $sub.EnumerateSubscriptionsByList($list.ID) 

在$订阅中,有相关的工作流程。希望它有帮助

+0

看到http://ranaictiu-technicalblog.blogspot.com/2013/05/programmatically-start-sharepoint-2013.html的详细信息 – 2013-09-30 21:28:33

这个MSDN blog post显示了大部分答案,但他们试图迭代列表而不是列表中的项目。以下是更新版本。

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

#-- 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 $items){ 
    #-- 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) 
}