如何从powershell启动工作流2013

时间:2013-02-23 20:20:08

标签: sharepoint-workflow

how to work with 2010 workflows using powershell上有一些指南。有人可以向我指出如何对2013工作流程做同样的事情吗?它们不再列在$list.WorkFlowAssociations内。

2 个答案:

答案 0 :(得分:4)

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

在$ subscriptions内部,有相关的工作流程。希望它有所帮助

答案 1 :(得分:4)

这个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)
}