Home > Workflow Manager > Listing all scopes in a Workflow Manager instance using PowerShell

Listing all scopes in a Workflow Manager instance using PowerShell

One of the pains I have encountered with setting up the Workflow Manager for use with SharePoint is that there is no clear visibility into the scopes that are currently on the Workflow Manager farm. It was hard to understand what scopes were already created, which of those were active, what the parent-child hierarchical relationships among those were and what applications were connected to those scopes.

So I tried to figure out if there was a way through OM code to get to this information or at least as much of it as I can get to without spending a whole lot of time and research. And below is what I could whip up.

param([parameter(mandatory=$true)][string]$Endpoint, [string]$Path = "/", [string]$Parent = "None")

[Reflection.Assembly]::Load("Microsoft.Workflow.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35") | Out-Null
Write-Output ""

function WriteScopeInfo([string]$scopeUri, [string]$path, [string]$parent) {
    $scopePath = $scopeUri + $path
    $client = New-Object -TypeName "Microsoft.Workflow.Client.WorkflowManagementClient" -ArgumentList $scopePath
    $manager = $client.CurrentScope
    $scope = $manager.Get()

    Write-Output "Name: `t`t`t$($scope.DisplayName)"
    Write-Output "Path: `t`t`t$($scope.Path)"
    Write-Output "Status: `t`t$($scope.Status.ToString())"
    Write-Output "User Comments: `t$($scope.UserComments)"
    Write-Output "Parent: `t`t$parent"
    Write-Output "Children: `t`t$($scope.ChildScopeCount)"
    Write-Output ""

    if ($scope.ChildScopeCount -gt 0) {
        $manager.GetChildScopes() | % { WriteScopeInfo $scopeUri $_.Path $scope.Path }
    }
}

WriteScopeInfo $Endpoint $Path $Parent

Note that the script requires 3 inputs, one of which is mandatory. The Endpoint parameter requires the URL to the workflow endpoint. This will likely be a web application on port 12290 or 12291 depending on whether you set up the Workflow Manager farm to just use HTTPS (which is the default) or also HTTP. Please refer to this post if you are not sure how to set up the Workflow Manager farm.

The other two parameters are just used to kick things off for the scope discovery function. The first called Path is used to determine the node in the scope tree that you want to begin with. By default, this assumes the value “/” representing the root scope on the farm. But if I know of another scope somewhere down the tree and the branches and spring thenceforth are the only ones I am concerned with, I would pass it so – “/myscope/subscope”. The second called Parent is only required to identify the parent of the scope node that I am starting at. It is not really required and assumes the value “None” by default.

When run the script produces an output as shown below. As you can see, I am providing the endpoint URL of the Workflow Manager instance installed on my machine.

clip_image001

For those that are unable to use PowerShell, here is the C# version of the same thing.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Workflow.Client;

namespace WorkflowClient
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string workflowEndpoint = string.Empty;
                if (args.Length < 1)
                {
                    Console.Write("Provide workflow endpoint URL: ");
                    workflowEndpoint = Console.ReadLine();
                }
                else
                {
                    workflowEndpoint = args[0];
                }
                Console.WriteLine("");
                WriteScopeInfo(workflowEndpoint, "/", "None");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);
            }
            finally
            {
                Console.WriteLine("Press any key to end...");
                Console.ReadKey(true);
            }
        }

        private static void WriteScopeInfo(string scopeUri, string path, string parent)
        {
            try
            {
                WorkflowManagementClient client = new WorkflowManagementClient(scopeUri + path);
                ScopeManager manager = client.CurrentScope;
                ScopeDescription scope = manager.Get();

                Console.WriteLine("Name: " + scope.DisplayName);
                Console.WriteLine("Path: " + scope.Path);
                Console.WriteLine("Status: " + scope.Status.ToString());
                Console.WriteLine("User Comments: " + scope.UserComments);
                Console.WriteLine("Parent: " + parent);
                Console.WriteLine("Children: " + scope.ChildScopeCount.ToString());
                Console.WriteLine("");

                if (scope.ChildScopeCount > 0)
                {
                    Collection<ScopeDescription> children = manager.GetChildScopes();
                    foreach (ScopeDescription child in children)
                    {
                        WriteScopeInfo(scopeUri, child.Path, scope.Path);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);
            }
        }
    }
}

I hope to be able to use this to keep things clean/sane when I have more applications using my workflow farm and needing more scopes and child scopes.

Advertisements
  1. H
    June 20, 2014 at 1:10 AM

    Cool Thanks!

  1. December 12, 2013 at 6:30 AM
  2. February 27, 2014 at 1:40 PM
  3. November 12, 2015 at 6:04 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: