none
SharePoint 2013 Online: List of all suspended workflows

    Question

  • Is there a powershell script or service out there that gives you a list of all workflow statuses? Primarily we are looking for a way to get a list of all current suspended workflows.

    Thanks,

    -Link

    Update: With the help of stack exchange a user gave me this list. http://www.codeproject.com/Articles/607127/Using-SharePoint-Workflow-Services-JS-API

    If there are still other solutions to this problem other than the link above I would appreciate it. 

    Thursday, October 30, 2014 8:16 PM

Answers

  • Hi,

    Please refer to technet gallery I have created PowerShell utility to show the workflow status for each list items for the SharePoint Online site.  You can download and modify the script to show only for suspended workflow status instead of all status.

    Workflow Status for List Items - SharePoint Online

    SharePoint Online (O365): PowerShell Script to get Workflow status

    Main code for displaying the status, complete script can be downloaded from the above link.

     foreach($workflowSubscription in $workflowSubscriptions)
                {            
                    Write-Host "**************************************************************************************"
                    Write-Host "List -"$list.Title " Workflow - "$workflowSubscription.Name -ForegroundColor Green
                    Write-Host "***************************************************************************************"
                    Write-Host ""
    
                    $camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
                    $camlQuery.ViewXml = "<View> <ViewFields><FieldRef Name='Title' /></ViewFields></View>";
                    $listItems = $list.GetItems($camlQuery);
                    $clientContext.Load($listItems);
                    $clientContext.ExecuteQuery();
    
                    foreach($listItem in $listItems)
                    {
                        $workflowInstanceCollection = $workflowInstanceSevice.EnumerateInstancesForListItem($list.Id, $listItem.Id);
                        $clientContext.Load($workflowInstanceCollection);
                        $clientContext.ExecuteQuery();
                        foreach ($workflowInstance in $workflowInstanceCollection)
                        {
                           Write-Host "List Item Title:"$listItem["Title"] 
                           Write-Host "Workflow Status:"$workflowInstance.Status 
                           Write-Host "Last Updated:"$workflowInstance.LastUpdated
                           Write-Host ""
                        }
                    }                   
                    Write-Host ""
                    
                }

    Please mark it answered, if your problem resolved or helpful.

    Saturday, November 1, 2014 10:34 AM

All replies

  • Hi Lincoln,

    According to your description, my understanding is that you want to list all suspended workflows in SharePoint Online.

    For SharePoint On-premise, we can use PowerShell commands with SPWorkflowState enumeration to classify the workflow instances.

    More information, you can refer to the links:

    http://www.codeproject.com/Articles/679628/Easiest-Way-of-Cancelling-All-S

    http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.workflow.spworkflowstate(v=office.15).aspx

    You can try to change the commands in the above link as the SharePoint Online PowerShell cmdlets:

    http://technet.microsoft.com/en-us/library/fp161364(v=office.15).aspx

    In addition, as this issue is related to SharePoint Online, you can also create a new thread on Office 365 forum, more experts will assist you with SharePoint Online.

    Office 365 forum:

    http://community.office365.com/en-us/f/default.aspx

    Best Regards,

    Wendy


    Wendy Li
    TechNet Community Support

    Friday, October 31, 2014 8:19 AM
    Moderator
  • Hi,

    Please refer to technet gallery I have created PowerShell utility to show the workflow status for each list items for the SharePoint Online site.  You can download and modify the script to show only for suspended workflow status instead of all status.

    Workflow Status for List Items - SharePoint Online

    SharePoint Online (O365): PowerShell Script to get Workflow status

    Main code for displaying the status, complete script can be downloaded from the above link.

     foreach($workflowSubscription in $workflowSubscriptions)
                {            
                    Write-Host "**************************************************************************************"
                    Write-Host "List -"$list.Title " Workflow - "$workflowSubscription.Name -ForegroundColor Green
                    Write-Host "***************************************************************************************"
                    Write-Host ""
    
                    $camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
                    $camlQuery.ViewXml = "<View> <ViewFields><FieldRef Name='Title' /></ViewFields></View>";
                    $listItems = $list.GetItems($camlQuery);
                    $clientContext.Load($listItems);
                    $clientContext.ExecuteQuery();
    
                    foreach($listItem in $listItems)
                    {
                        $workflowInstanceCollection = $workflowInstanceSevice.EnumerateInstancesForListItem($list.Id, $listItem.Id);
                        $clientContext.Load($workflowInstanceCollection);
                        $clientContext.ExecuteQuery();
                        foreach ($workflowInstance in $workflowInstanceCollection)
                        {
                           Write-Host "List Item Title:"$listItem["Title"] 
                           Write-Host "Workflow Status:"$workflowInstance.Status 
                           Write-Host "Last Updated:"$workflowInstance.LastUpdated
                           Write-Host ""
                        }
                    }                   
                    Write-Host ""
                    
                }

    Please mark it answered, if your problem resolved or helpful.

    Saturday, November 1, 2014 10:34 AM
  • You are a talented PowerShell scripter.  Thank you for your help!
    Saturday, November 1, 2014 7:33 PM
  • Alright you got me. I've been trying to add 

    if($item.Workflows | where {$_.InternalStatus -eq "Suspended"})

    to the code you supplied but I cant seem to get it to work how I wish. 

    Full code:

    cls
    #Import SharePoint Online Management Shell
    Import-Module Microsoft.Online.SharePoint.Powershell -ErrorAction SilentlyContinue
    
    Add-PSSnapIn Microsoft.SharePoint.PowerShell  -ErrorAction SilentlyContinue
    
    #region Input Variables 
    
    $SiteUrl = "https://changed-for-anonymity.sharepoint.com" #Replace the URL
    
    
    $UserName = Read-Host -Prompt "Enter User Name"
    $SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString
    
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
    
    #endregion
    
    #region Connect to SharePoint Online tenant and Create Context using CSOM
    
    Try
    {
        #region Load SharePoint Client Assemblies
    
    	Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
    	Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
        Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.WorkflowServices.dll"
    
        #endregion
    
         
        #region connect/authenticate to SharePoint Online and get ClientContext object.. 	
    
        $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
        $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword) 
        $clientContext.Credentials = $credentials
    
        Write-Host "Connected to SharePoint Online site: " $SiteUrl -ForegroundColor Green
        Write-Host ""
    
        #endregion
    
    
    }
    Catch
    {
        $SPOConnectionException = $_.Exception.Message
        Write-Host ""
        Write-Host "Error:" $SPOConnectionException -ForegroundColor Red
        Write-Host ""
        Break
    }
    
    #endregion
    
    if (!$clientContext.ServerObjectIsNull.Value) 
    { 
            $web = $clientContext.Web
            $lists = $web.Lists
    	    $clientContext.Load($lists);
    	    $clientContext.ExecuteQuery();
    
            $workflowServicesManager = New-Object Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager($clientContext, $web);
            $workflowSubscriptionService = $workflowServicesManager.GetWorkflowSubscriptionService();
            $workflowInstanceSevice = $workflowServicesManager.GetWorkflowInstanceService();
    
            
    
            Write-Host ""
            Write-Host "Exporting Lists" -ForegroundColor Green
            Write-Host ""
    
            foreach ($list in $lists)         
            {   
                if($item.Workflows | where {$_.InternalStatus -eq "Suspended"})
                {
                    $workflowSubscriptions = $workflowSubscriptionService.EnumerateSubscriptionsByList($list.Id);
                    $clientContext.Load($workflowSubscriptions);                
                    $clientContext.ExecuteQuery();                
                    foreach($workflowSubscription in $workflowSubscriptions)
                    {            
                        Write-Host "**************************************************************************************"
                        Write-Host "List -"$list.Title " Workflow - "$workflowSubscription.Name -ForegroundColor Green
                        Write-Host "**************************************************************************************"
                        Write-Host ""
    
                        $camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
                        $camlQuery.ViewXml = "<View> <ViewFields><FieldRef Name='Title' /></ViewFields></View>";
                        $listItems = $list.GetItems($camlQuery);
                        $clientContext.Load($listItems);
                        $clientContext.ExecuteQuery();
    
                        foreach($listItem in $listItems)
                        {
                            $workflowInstanceCollection = $workflowInstanceSevice.EnumerateInstancesForListItem($list.Id, $listItem.Id);
                            $clientContext.Load($workflowInstanceCollection);
                            $clientContext.ExecuteQuery();
                            foreach ($workflowInstance in $workflowInstanceCollection)
                            {
                               Write-Host "List Item Title:"$listItem["Title"] 
                               Write-Host "Workflow Status:"$workflowInstance.Status 
                               Write-Host "Last Updated:"$workflowInstance.LastUpdated
                               Write-Host ""
                            }
                        }                   
                        Write-Host ""
                    
                    }
                }
               
            }  
        }                         
            
            #endregion
        
        
        
        
    

    Monday, November 3, 2014 5:12 PM
  • Hi Lincoln,

    Did you receive any error while running the Powershell?


    Thanks and Regards Rahul Dagar

    Monday, November 3, 2014 5:19 PM
  • No error. It works fine with out the addition of the code. When i added the if statement it gives back nothing.
    Monday, November 3, 2014 5:21 PM
  • Hi Lincoln,

    Unfortunately CSOM and JSOM "ListItem" object does not support "Workflows" collection.  This is only supported in Server Side object model.  So, I have used the following approach.

    http://msdn.microsoft.com/en-us/library/office/jj245356(v=office.15).aspx

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.listitem_members(v=office.15).aspx

    Please use the following code to meet your requirement.  And also I am only iterating Lists which have workflow association.

    cls
    #Import SharePoint Online Management Shell
    Import-Module Microsoft.Online.SharePoint.Powershell -ErrorAction SilentlyContinue
    
    Add-PSSnapIn Microsoft.SharePoint.PowerShell  -ErrorAction SilentlyContinue
    
    #region Input Variables 
    
    $SiteUrl = "https://xxx.sharepoint.com" #Replace the URL
    
    
    $UserName = Read-Host -Prompt "Enter User Name"
    $SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString
    
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
    
    #endregion
    
    #region Connect to SharePoint Online tenant and Create Context using CSOM
    
    Try
    {
        #region Load SharePoint Client Assemblies
    
    	Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
    	Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
        Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.WorkflowServices.dll"
    
        #endregion
    
         
        #region connect/authenticate to SharePoint Online and get ClientContext object.. 	
    
        $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
        $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword) 
        $clientContext.Credentials = $credentials
    
        Write-Host "Connected to SharePoint Online site: " $SiteUrl -ForegroundColor Green
        Write-Host ""
    
        #endregion
    
    
    }
    Catch
    {
        $SPOConnectionException = $_.Exception.Message
        Write-Host ""
        Write-Host "Error:" $SPOConnectionException -ForegroundColor Red
        Write-Host ""
        Break
    }
    
    #endregion
    
    if (!$clientContext.ServerObjectIsNull.Value) 
    { 
            $web = $clientContext.Web
            $lists = $web.Lists
    	    $clientContext.Load($lists);
    	    $clientContext.ExecuteQuery();
    
            $workflowServicesManager = New-Object Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager($clientContext, $web);
            $workflowSubscriptionService = $workflowServicesManager.GetWorkflowSubscriptionService();
            $workflowInstanceSevice = $workflowServicesManager.GetWorkflowInstanceService();
    
            
    
            Write-Host ""
            Write-Host "List Workflows" -ForegroundColor Green
            Write-Host ""
    
            foreach ($list in $lists)         
            {   
                $workflowSubscriptions = $workflowSubscriptionService.EnumerateSubscriptionsByList($list.Id);
                $clientContext.Load($workflowSubscriptions);                
                $clientContext.ExecuteQuery();                
                foreach($workflowSubscription in $workflowSubscriptions)
                {            
                    Write-Host "**************************************************************************************"
                    Write-Host "List -"$list.Title " Workflow - "$workflowSubscription.Name -ForegroundColor Green
                    Write-Host "***************************************************************************************"
                    Write-Host ""
    
                    $camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
                    $camlQuery.ViewXml = "<View> <ViewFields><FieldRef Name='Title' /></ViewFields></View>";
                    $listItems = $list.GetItems($camlQuery);
                    $clientContext.Load($listItems);
                    $clientContext.ExecuteQuery();
    
                    foreach($listItem in $listItems)
                    {
                        $workflowInstanceCollection = $workflowInstanceSevice.EnumerateInstancesForListItem($list.Id, $listItem.Id);
                        $clientContext.Load($workflowInstanceCollection);
                        $clientContext.ExecuteQuery();
                        foreach ($workflowInstance in $workflowInstanceCollection)
                        {
                           if($workflowInstance.Status -eq "Suspended")
                           {
                                Write-Host "List Item Title:"$listItem["Title"] 
                                Write-Host "Workflow Status:"$workflowInstance.Status 
                                Write-Host "Last Updated:"$workflowInstance.LastUpdated
                                Write-Host ""
                           }
                        }
                    }                   
                    Write-Host ""
                    
                }
    
               
            }  
        }                         
            
            #endregion
        
        
        
        

    Please mark it answered, if your problem resolved or helpful.


    Monday, November 3, 2014 5:53 PM
  • Wicked cool! Thanks!
    Monday, November 3, 2014 5:58 PM