Quantcast
Channel: SharePoint 2013 - Using SharePoint Designer, InfoPath and Other Customizations forum
Viewing all articles
Browse latest Browse all 9368

Cancel All Workflows

$
0
0

I have a situation where we have many workflows running.  I don't know which documents started them and we have a lot.  It would be a huge task to go in one by one to find and end them.

When I get into Library Settings - > Workflow Settings it shows the count under "Workflows in Progress".  They are looping and eating up the CPU.

I found code on the forum and modified it.  I ran it on the entire site changing libraries and folders.  It finds no workflows.  Can anyone see an issue with this PS code?

Thanks.

#Your SharePoint Site URL
$web = Get-SPWeb "MyUrl";
$web.AllowUnsafeUpdates = $true;   
 
$list = $web.Lists["MyList"];

Write-Host "Lib Name :" $list.Title;
 
$query = New-Object Microsoft.SharePoint.SPQuery
$query.Folder = $list.RootFolder.SubFolders["MyFolder"]
$items = $list.GetItems($query)
 
# Iterate through all Items in List and all Workflows on Items. 
foreach ($oitem in $items) {
  Write-Host "In 1st loop Workflow: " $oitem.Name;    <----- I see this for every doc
  Write-Host "Workflow: " $oitem.Workflows;  <---  This is blank for every doc
   foreach ($wf in $oitem.Workflows) {    <---- It never gets in this loop
    Write-Host "In 2nd loop Workflow: " $oitem.Title;
      #Cancel Workflows 
      [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf); 
      Write-Host "Workflow cancelled for : " $oitem.Title;
   } 

$web.Dispose();


Tom


Viewing all articles
Browse latest Browse all 9368


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>