使用 PowerShell 取消多个 SharePoint 工作流
如何取消 SharePoint (2010) 列表中所有正在运行的工作流?
我通过 technet 找到了这个脚本。
代码:
using (SPSite oSite = new SPSite("<your url>"))
{
foreach (SPWeb oWeb in oSite.AllWebs)
{
oWeb.AllowUnsafeUpdates = true;
// stop list workflows
foreach (SPList list in oWeb.Lists)
{
foreach (SPListItem oItem in list.Items)
{
foreach (SPWorkflow workflow in oItem.Workflows)
{
SPWorkflowManager.CancelWorkflow(workflow);
}
}
}
// stop site workflows
foreach (SPWorkflow workflow in oWeb.Workflows)
{
SPWorkflowManager.CancelWorkflow(workflow);
}
oWeb.AllowUnsafeUpdates = false;
oWeb.Dispose();
}
}
非常感谢您的帮助。
How is it possible to cancel all running workflows in a SharePoint (2010) List?
I found this script via technet.
CODE:
using (SPSite oSite = new SPSite("<your url>"))
{
foreach (SPWeb oWeb in oSite.AllWebs)
{
oWeb.AllowUnsafeUpdates = true;
// stop list workflows
foreach (SPList list in oWeb.Lists)
{
foreach (SPListItem oItem in list.Items)
{
foreach (SPWorkflow workflow in oItem.Workflows)
{
SPWorkflowManager.CancelWorkflow(workflow);
}
}
}
// stop site workflows
foreach (SPWorkflow workflow in oWeb.Workflows)
{
SPWorkflowManager.CancelWorkflow(workflow);
}
oWeb.AllowUnsafeUpdates = false;
oWeb.Dispose();
}
}
Many thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试一试这个。
我对其进行了修改,以便在特定网络上的特定列表上完成。
对我来说效果很好。让我知道它是否适合您。
Give this one a shot.
I modified it so that it is done on a specific list on a specific web.
Worked just fine for me. Let me know if it works for you.
这个脚本对我来说非常有用。我进行了修改,允许我取消一个列表中的所有工作流程或仅取消一个工作流程,并认为我也将其发布在这里:
This script has been wickedly useful to me. I make a modification to allow me to cancel all the workflows in one list or just one workflow and thought I would post it here too:
试试这个(C# 到 powershell 的简单“翻译”):
Try this (simple "translation" of C# to powershell):
这是我修改后的脚本:
这是我得到的错误(我使用的是德国本地化版本的服务器和共享点):
运行脚本的用户是机器本身的管理员,站点收集管理员和sql管理员。我还用这个帐户创建了子网站,所以我不认为用户访问会成为问题。
我找到了这个答案(枚举集合时 PowerShell 和 C# 之间的差异)但我不知道如何为我使用这些信息?!
here is my modified script:
an this is the error i get (i am using a german localized version of the server and sharepoint):
the user runnig the script is admin on the machine it self, sitecollection admin and sql-admin. i also created the subsite with this account, so i don't think that useracces would be the problem.
I found this answer (Differences Between PowerShell and C# when Enumerating a Collection) but i don't get a clue how to use this information for me?!