List Site Collection Workflows

By James|10/10/2019|,

Would you like to know how many workflows are in a given site collection?  How many of those workflows are currently running?  How many old versions of workflows you have laying around?  The following PowerShell script will crawl a site collection and enumerate all lists/libraries for workflow associations and report back useful information such as list name, workflow name and workflows running.

# Title:   Locate-SiteWorkflows.ps1
# Version: 1.0, 08OCT19
# Author:  James Sanders
# Purpose: Find all workflows in a given site collection

# Add the PowerShell Snap-In
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

$results = @()
$siteColl =  "https://your.portal/site_collection"
$site = Get-SPSite -Identity $siteColl -Limit All
ForEach($web in $site.AllWebs) {
  Write-Host "`nProcessing web site: $($web.Url)`n"
  ForEach($list in $web.Lists) {
    Write-Host "Inspecting list: $($list.Title) ... " -NoNewLine
    If ($list.WorkflowAssociations -ne $null) {
      Write-Host "Workflows located!"
      ForEach($wflowAssociation in $list.WorkflowAssociations) {
        $RowDetails =  @{
          "List Name"         = $wflowAssociation.ParentList.Title
          "Workflow Name"     = $wflowAssociation.Name
          "Running Instances" = $wflowAssociation.RunningInstances
          "Created On"        = $wflowAssociation.Created
          "Modified On"       = $wflowAssociation.Modified
          "Parent Web"        = $wflowAssociation.ParentWeb
          "Task List"         = $wflowAssociation.TaskListTitle
          "History List"      = $wflowAssociation.HistoryListTitle
          "Site URL"          = $myWeb.Url
        }  
        $results += New-Object PSObject -Property $RowDetails
      }
    }
    Else {Write-Host}
  }
}

$csvFile = [Environment]::GetFolderPath("Desktop") + "\workflowList.csv"
$results | Select-Object "List Name", "Workflow Name", "Running Instances", "Created On","Modified On","Parent Web", "Task List","History List", "Site URL" | export-csv -Path $csvFile -NoTypeInformation

 

Copyright 2011 - 2024 The Lazy IT Admin | All Rights Reserved
menu-circlecross-circle linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram