使用PowerShell在列表中更改项目时取消工作流程 [英] Cancel a workflow when a item is changed in a list using PowerShell

查看:66
本文介绍了使用PowerShell在列表中更改项目时取消工作流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了取消使用PowerShell完成的所有工作流程的代码。然而,我正在寻找代码(使用powershell),当代表当前项目时,该代码将取消特定列表的特定工作流程上的工作流程(进行中):称为"待处理"
更改为其他值。使用PowerShell可以使用哪些代码?

$
这是我找到的代码: 



#Your Shaeproint站点URL

$ web = Get-SPWeb" http://yoursharepointserver.com/yoursubsite" ;;

$ web.AllowUnsafeUpdates = $ true;    
$


#您的清单名称

$ list = $ web.Lists [" YourListName"];

$ count = 0



#Loop遍历列表中的所有项目,然后遍历每个列表项目上的所有工作流程。         
$
foreach($ listItem in $ list.Items) 

{

    foreach($ listItem.Workflows中的$ workflow) 

    {

        #Disregard已完成工作流程 

        if(($ listItem.Workflows | where {$ _。InternalState -ne" Completed"})-ne $ null)

        {

            #Cancel工作流程        

            [Microsoft.SharePoint.Workflow.SPWorkflowManager] :: CancelWorkflow($工作流程);      

            write-output"取消工作流程:" $ listItem.Title;  

        }¥b $ b    }
}
$ $ $ $ $ $ $ $ $ $ $ $ "padding-right:0px; line-height:inherit; font-family:'Segoe UI',Segoe,'Helvetica Neue','Lucida Grande',Arial,sans-serif; font-size:15px; vertical-align:基线;清除:两者;颜色:#444444">
使用PowerShell取消所有工作流程



如果您使用的是SharePoint On-Prem,并且需要取消特定列表中的所有正在进行的SharePoint工作流,则应使用以下Powershell脚本

#Your Shaeproint站点URL 


web = Get-SPWeb" http://yoursharepointserver.com/yoursubsite" ;;


web.AllowUnsafeUpdates =


I found code to cancel all workflows that are completed using powershell. However I was looking for code (using powershell) that will cancel a workflow (In Progress) on a specific workflow for a specific list when a current item: called "pending" is changed to a different value. What code would work using powershell?

Here is the code I found: 

#Your Shaeproint Site URL
$web = Get-SPWeb "http://yoursharepointserver.com/yoursubsite";
$web.AllowUnsafeUpdates = $true;    

#Your List Name
$list = $web.Lists["YourListName"];
$count = 0

#Loop through all Items in List then loop through all Workflows on each List Items.         
foreach ($listItem in $list.Items) 
{
    foreach ($workflow in $listItem.Workflows) 
    {
        #Disregard Completed Workflows 
        if(($listItem.Workflows | where {$_.InternalState -ne "Completed"}) -ne $null)
        {
            #Cancel Workflows        
            [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($workflow);      
            write-output "Workflow cancelled for : " $listItem.Title;  
        }
    }
}
$web.Dispose();

解决方案

To cancel all workflow using PowerShell

If you are using SharePoint On-Prem and you need to cancel all SharePoint Workflows in Progress for a specific list, you should use the below Powershell script

#Your Shaeproint Site URL


web = Get-SPWeb "http://yoursharepointserver.com/yoursubsite";


web.AllowUnsafeUpdates =


这篇关于使用PowerShell在列表中更改项目时取消工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆