2013-02-23 39 views

回答

4
$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

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) 
} 
相關問題