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 "https://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

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

7 thoughts on “SharePoint Workflows Inventory Report using PowerShell

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

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

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

    Reply
  • is it possible to backup SharePoint designer workflows with Powershell scripts

    Reply
  • Thank you…this was exactly what I needed!

    Reply
  • 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
  • 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

Your email address will not be published. Required fields are marked *