Posted on:
Categories: PowerShell;SharePoint
Description:

Scenario

SharePoint 2013 Workflow Manager is in a broken state. You must find all of the instances of SharePoint 2013 Workflows in order to gauge the impact of the problem.

Solution

Knowing that Workflow Manager is in a broken state, we won't be able to use its API to find all the workflows. From experience, I know that SharePoint 2010 Workflows are stored in the site in a library called "Workflows". At this point, I went to my DEV environment and created a 2013 workflow and started looking around for it. Luckily, the 2013 workflows work the same way and I didn’t have to open up to code to find them.

The following script will return all sites which contain a SharePoint 2013 Workflow. The results will be output in a csv format with | as the delimiter.

#----------------------------------------------------------------------------- 
# Name:               Get-SP2013Workflows.ps1  
# Description:         This script will find SharePoint 2013 Workflows 
#                     
# Usage:            Run the function
# By:                 Ivan Josipovic, Softlanding.ca  
#----------------------------------------------------------------------------- 
 
Function Get-SP2013Workflows(){
 foreach ($web in get-spsite -limit all | get-spweb -limit all ){
  if ($web.folders["wfsvc"] -ne $null) {
   foreach ($wfFolder in $web.folders["wfsvc"].subfolders | ? {$_.name -ne "forms"} ) {
    $xaml = $wfFolder.files | ? {$_.name.tolower().EndsWith(".xaml")};
    $xamlStream = new-object System.IO.StreamReader($($xaml.OpenBinaryStream()));
    $xml = [xml]$xamlStream.ReadToEnd();
    Write-Host "$($web.url)|$($xml.Activity.Class.ToString().TrimEnd(".MTW"))";
   }
  }
 }
}

#Get-SP2013Workflows();