Answered by:
Powershell - stop all running workflows

Question
Answers
-
Just an idea to get you started...
If you can read C# skills you convert the C# code here into a PowerShell script: http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e5fc79f8-ca3a-421a-ab8a-78fcb3365b46
(Most anything you can do in SharePoint with C# you can also do with PowerShell.)
Mike Smith TechTrainingNotes.blogspot.com- Marked as answer by Serge Luca [MVP]MVP Sunday, June 19, 2011 10:42 AM
-
I haven't tested my code, but this should also helps (don't forget that in SharePoint 2010 we have both site workflows and lits workflows)
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();
}
}
}
}
Serge Luca; MVP blog: http://sergeluca.spaces.live.com Devoteam Belgium. http://twitter.com/sergeluca- Marked as answer by Serge Luca [MVP]MVP Sunday, June 19, 2011 10:42 AM
All replies
-
Just an idea to get you started...
If you can read C# skills you convert the C# code here into a PowerShell script: http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/e5fc79f8-ca3a-421a-ab8a-78fcb3365b46
(Most anything you can do in SharePoint with C# you can also do with PowerShell.)
Mike Smith TechTrainingNotes.blogspot.com- Marked as answer by Serge Luca [MVP]MVP Sunday, June 19, 2011 10:42 AM
-
I haven't tested my code, but this should also helps (don't forget that in SharePoint 2010 we have both site workflows and lits workflows)
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();
}
}
}
}
Serge Luca; MVP blog: http://sergeluca.spaces.live.com Devoteam Belgium. http://twitter.com/sergeluca- Marked as answer by Serge Luca [MVP]MVP Sunday, June 19, 2011 10:42 AM
-