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 ( http://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.

Advertisements