SharePoint Workflows Inventory Report using PowerShell

In continuation with my other post: Workflows Inventory Report for SharePoint, which was done using C# object model code, This is a PowerShell version to find all workflows deployed in the SharePoint environment to generate the workflows Inventory report.

Basically, this script iterates through all site collections-sites-List objects to fetch workflow data such as: Workflow Name, Running instances, etc.

#For SharePoint 2007 Compatibility
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

Function global:Get-SPWebApplication($WebAppURL)
{
 return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
}

#Function to Get the workflow inventory for the entire web application
function Get-WorkflowInventory([string] $WebAppURL)
{
    #Get the Web Application URL
    $WebApp = Get-SPWebApplication $WebAppURL  
 
    #Iterate through each site collection
    foreach ($Site in $WebApp.Sites)
          {                              
                #Loop through each site     
                foreach ($Web in $Site.AllWebs)
                   {
                    #Loop through each list
                    foreach ($List in $Web.Lists)
                      {
                         # Leave hidden Lists and Libraries
                         if($List.Hidden -eq $false)
                         {
                            foreach ($WorkflowAssociation in $List.WorkflowAssociations)
                            {
                                #Leave the "Previous Versions"
                                if($WorkflowAssociation.Name.Contains("Previous Version") -eq $false)
                                    {
                                       $data = @{
                                        "Site" = $Site.Rootweb.Title
                                        "Web" = $Web.Title
                                        "Web URL" = $Web.Url
                                        "List Name" = $List.Title
                                        "List URL" =  $Web.Url+"/"+$List.RootFolder.Url
                                        "Workflow Name" = $WorkflowAssociation.Name
                                        "Running Instances" = $WorkflowAssociation.RunningInstances
                                        }
                                        
                                        #Create an object
                                        New-Object PSObject -Property $data
                                    }
                              }
                          }                    
                    }
                     $Web.Dispose()                  
                }
                $Site.Dispose()                   
    }
} 

#call the function
Get-WorkflowInventory "http://sharepoint.crescent.com" | Export-Csv -NoTypeInformation -Path D:\Reports\WorkflowInventory.csv

write-host "Workflows Inventory report has been generated successfully!"

Tail: How to find all SharePoint designer workflows?
While the above workflow gives workflow data on all workflows, it’s possible to find only SharePoint designer made workflows by checking the below condition:

if( ($WorkflowAssociation -eq $null) -and ($WorkflowAssociation.InternalName.Contains("Xoml")))
{
    #This is a SharePoint Designer Workflow
}

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

7 thoughts on “SharePoint Workflows Inventory Report using PowerShell

  • April 13, 2021 at 10:02 PM

    Your scripts are always helpful. Just what I needed with a little tweaking.

    Reply
  • December 16, 2019 at 6:20 AM

    How to get SharePoint 2010/2013 List, Site, Reusable, Nintex workflows using Powershell script

    Reply
  • December 19, 2018 at 9:26 AM

    How to get “workflow type” and “last modified Date”? Can you please help me on this.

    Reply
  • November 15, 2017 at 3:17 PM

    is it possible to backup SharePoint designer workflows with Powershell scripts

    Reply
  • June 7, 2017 at 2:24 PM

    Thank you…this was exactly what I needed!

    Reply
  • March 30, 2016 at 7:57 AM

    Hello,

    I included the above code to get the sharepoint designer workflows but no data in output file.

    Here is the script :

    foreach ($WorkflowAssociation in $List.WorkflowAssociations)
    {
    #Leave the “Previous Versions”
    if($WorkflowAssociation.Name.Contains(“Previous Version”) -eq $false)
    {
    if( ($WorkflowAssociation -eq $null) -and ($WorkflowAssociation.InternalName.Contains(“Xoml”)))
    {
    $data = @{
    “Site” = $Site.Rootweb.Title
    “Web” = $Web.Title
    “Web URL” = $Web.Url
    “List Name” = $List.Title
    “List URL” = $Web.Url+”/”+$List.RootFolder.Url
    “Workflow Name” = $WorkflowAssociation.Name
    “Running Instances” = $WorkflowAssociation.RunningInstances
    }

    #Create a object
    New-Object PSObject -Property $data

    Could you please help me on this.

    Thanks.

    Reply
  • June 4, 2015 at 8:01 PM

    This script did not work for me. I get the following error when I run the PS script:
    You cannot call a method on a null-valued expression.
    At D:workflow.ps1:48 char:34
    + $Web.Dispose <<<< () + CategoryInfo : InvalidOperation: (Dispose:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull You cannot call a method on a null-valued expression. At D:workflow.ps1:50 char:30 + $Site.Dispose <<<< () + CategoryInfo : InvalidOperation: (Dispose:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

    Reply

Leave a Reply