Tuesday, July 16, 2013

SharePoint Workflows Inventory Report using PowerShell

In continuation with my another 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 a 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, its 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
              }



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

2 comments :

  1. 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

    ReplyDelete
  2. 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.

    ReplyDelete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...