SharePoint 2013 has a new workflow engine. I’m assuming that that is no news any more.

So if the workflows are now managed through Workflow Manager 1.0, most likely the workflow instances are accessible through the workflow Manager services.

When you now try to get the Workflow instances through PowerShell you will find that only the 2010 workflows can still be found. If you want to get to the 2013 workflows through PowerShell you have to do a bit more work.

I couldn’t find any way to access the Workflows easily. After a bit of googling I found a good example doing something similar ( https://lennytech.wordpress.com/2013/08/12/listing-all-scopes-in-a-workflow-manager-instance-using-powershell/)

But still this doesn’t give me the instances of the workflows.

So I thought I better debug through the object model a bit and I found the answer to displaying all the Workflow Manager’s SharePoint 2013 workflow instances using PowerShell. Hopefully this will help someone.

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

function WriteWFInfo([string]$scopeUri, [string]$path) {
    $scopePath = $scopeUri + $path
    $client = New-Object -TypeName "Microsoft.Workflow.Client.WorkflowManagementClient" -ArgumentList $scopePath    
    $client.Instances.Get()

}

WriteWFInfo "http://devsp:12291" "/SharePoint/default/6146d95b-34d9-43a3-8013-a0ce8fc8779d/be8caf40-7d9b-493b-b6e1-1e1f4545b0b3"

In the above example I set my scope Path so that I wouldn’t get too many results back.

I took this above example a bit further and started to look at what is created when a workflow is assigned to a list.

So what did I now learn?

Now that workflow manager isn’t part of SharePoint you actually have to be very careful when you deploy solutions. Typically I create a PowerShell script that create a site collection within an application. And when I want to update my solution (pre-production) I simply run the PowerShell script and all is put back into place.

Ai, can’t do this anymore like this as every time I activate a workflow as part of my deployment and delete the site collection (without deactivating the workflow feature) I’m ending up with yet another Workflow Scope ( What is that????).

So maybe just deactivating the workflow feature would to the trick. So I included in my deployment script a bit of code to disable my workflow but I’m still ending up with more Workflow Scopes. aahhh, I don’t know what they are and I’m getting more of them. This is not making me feel comfortable.

I deleted the workflow form within SharePoint, SharePoint Designer, Features etc. but still the Workflow Scope is kept.

It looks like SharePoint doesn’t want to clean up Workflow Manager workflows properly.

Watch this space …

Follow my blog and I will let you know if I find a solution.

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

2 thoughts on “SharePoint 2013 – Accessing workflows in PowerShell”
  1. The script looks like it should give me results. I used the listWorkflowScopes script you referenced in your article, which yielded 7 scopes. This is the staging area, so not problematic. but when I went to use your script to enumerate specific workflows within the scopes, your script did not yield any results. I substituted your , and substituted a few of the 7 scopes, one which had user comments and two Children, the script did not provide any results. it just gave me a new line in the PowerShell window.

    Code snippet:

    WriteWFInfo “https://WFMServer.domain.com:12290” “/SharePoint/default/38d0a08c-0fd6-4b6e-ac88-df4a7d902e23/b9410107-9127-405b-a665-6e4290abd30a”

    There were supposed to be two children…any help would be appreciated.

    1. Hi Paul,

      In the script in my post does $client get set ok? There are 2 points where things could fail:

      1. creating the $client object
      2. finding $client.Instances

      I would probably add some additional Write-Output lines there to see what client is set to and what client. Instances is set to.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading