当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 取消 SharePoint 中的工作流

作者:精品下载站 日期:2024-12-15 00:00:59 浏览:15 分类:玩电脑

使用 PowerShell 取消 SharePoint 中的工作流


要求:有一个大列表,附有工作流程。 SharePoint 开发团队要求取消在这些列表项上运行的多个工作流,将近 2000 个!

虽然取消单个项目的工作流程非常简单,但取消 1000 个项目的工作流程怎么样?这将是一项艰巨的任务,不是吗?

[玩转系统] 使用 PowerShell 取消 SharePoint 中的工作流

使用 PowerShell 终止 SharePoint 中的工作流:

那么,PowerShell 可以帮助取消 SharePoint 中的工作流。如果您必须取消所有列表项上的多个正在运行的工作流程,请使用以下 PowerShell 脚本:

取消列表上的所有工作流程:


$web = Get-SPWeb "https://your-sharepoint-site-url"

#List Name
$list = $web.Lists["Your-List-Name"]

# Iterate through all Items and all Workflows on Items
foreach ($item in $list.Items) 
 {
   foreach ($wf in $item.Workflows) 
     {
        #Cancel Workflows        
        [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf)      
     }
  }

要取消所有出错的工作流程,请使用以下条件:


foreach ($item in $list.Items) 
 {
   foreach ($wf in $item.Workflows) 
     {
        if($wf.InternalState -match 'Error')
         {
            #Cancel Workflows        
            [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf);      
         }
     }
 }

取消 SharePoint 中的工作流

让我们针对特定的工作流程:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$web = Get-SPWeb "https://your-sharepoint-site-url"

#Get the List
$list = $web.Lists["Your-List-Name"]

#Get the specific workflow, Associated with the list
$WorkFlowToCancel = "Approval Workflow"

# Iterate through all Items and all Workflows on Items
foreach ($item in $list.Items) 
{
   foreach ($wf in $item.Workflows) 
     {
        #Check for the particular workflow
        if( ($wf.ParentAssociation.Name -eq $WorkFlowToCancel) -and ($wf.IsCompleted -ne $true) -and($wf.StatusText -ne "Canceled"  )) 
        {
            write-host "Previous workflow status:"  $wf.InternalState
            #Cancel Workflow
            [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf)      
            write-host "Workflow Cancelled at $($list.title)! "
        }
     }
}

相关文章:如何使用 PowerShell 启动 SharePoint 工作流

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯