2

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.

Update:

Here is the script for receiving statuses of all workflow statuses. It need to be tweeked to only show only suspended, which I will post later. As of right now though it is a working turn key script. I hope you find it useful!

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 "Exporting Lists" -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)
                    {
                       Write-Host "List Item Title:"$listItem["Title"] 
                       Write-Host "Workflow Status:"$workflowInstance.Status 
                       Write-Host "Last Updated:"$workflowInstance.LastUpdated
                       Write-Host ""
                    }
                }                   
                Write-Host ""

            }


        }  
    }                         

        #endregion
  • try this link codeproject.com/Articles/607127/… from this use Enumerate workflow definitions of a site. But you have to tweak as per your requirment – Waqas Sarwar MVP Oct 30 '14 at 20:40
  • Ill take a look. Thank you! Could you submit this as a possible answer so I can mark it as correct for future people with this issue? – Lincoln Hach Yellick Oct 30 '14 at 21:41
1

Please try the below code from Using SharePoint 2013 Workflow Services JS API. You may have to tweak it according to your requirement.

(function () {

    // Getting client context and loading the current web
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    context.load(web);

    // Workflow Services API entry point - WorkflowServiceManager object
    var servicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
    context.load(servicesManager);

    var workflowDefinitions = servicesManager.getWorkflowDeploymentService().enumerateDefinitions(false);
    context.load(workflowDefinitions);

    context.executeQueryAsync(function (sender, args) {

        // enumerateDefinition returns ClientCollection object
        var definitionsEnum = workflowDefinitions.getEnumerator();

        var empty = true;

        console.log('Site ' + web.get_url() + ':');

        // Going through the definitions
        while (definitionsEnum.moveNext()) {

            var def = definitionsEnum.get_current();

            // Displaying information about this definition - DisplayName and Id
            console.log(def.get_displayName() + " (id: " + def.get_id() + ")");

            empty = false;

        }

        if (empty) {
           console.log('No 2013 workflows found.');
        }

    }, errFunc);


    // Error handling
    function errFunc(sender, args) {
        alert("Error occured! " + args.get_message());
    };

})();
  • Thanks for adding this. Ill be adding the script I come up with after I fiddle around with it. – Lincoln Hach Yellick Oct 30 '14 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.