Workflows are a quintessential example of automating manual tasks in SharePoint. Besides automations, they function as the heart of many organizations’ IT landscape by providing solutions such as approval mechanisms, document management, user onboarding, etc. The uses and benefits are many.
But looking through the lens of a Farm Admin or Site Collection Admin, there does not exist any report or out of the box means to provide a detailed list of workflows and their usage, dependent lists etc.
ShareGate has recently rolled out an update using which you can use to generate a very comprehensive report for Workflow usage in a site collection. And for others (like me!) who use PowerShell almost everywhere and tackle almost every scenario, welcome to my article!
This script will identify and find out the list of workflows that are published within a site collection. The idea is to iterate through all the child webs and within each web will investigate all the lists that are using workflows. This script can report all the OOTB workflows as well as SPD workflows. Please note that, this script cannot identify site workflows.
Script
- if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
- {
-
- Add-PSSnapin "Microsoft.SharePoint.PowerShell"
- }
-
- $results = @()
- $siteColl = "http://sharepoint.starkindustries.com/it"
-
- $site = Get-SPSite -Identity $siteColl -Limit All
- try
- {
- foreach ($myWeb in $site.AllWebs)
- {
- Write-Host "Looking in Web: " $myWeb.Url -ForegroundColor Red
- foreach($list in $myWeb.Lists)
- {
- if ($list.WorkflowAssociations -eq $true)
- {
- Write-Host $list.Title -ForegroundColor Blue
- foreach ($wflowAssociation in $list.WorkflowAssociations)
- {
- $RowDetails = @{
- "List Name" = $wflowAssociation.ParentList.Title
- "Workflow Name" = $wflowAssociation.InternalName
- "Running Instances" = $wflowAssociation.RunningInstances
- "Created On" = $wflowAssociation.Created
- "Modified On" = $wflowAssociation.Modified
- "Parent Web" = $wflowAssociation.ParentWeb
- "Task List" = $wflowAssociation.TaskListTitle
- "History List" = $wflowAssociation.HistoryListTitle
- }
-
- $results += New-Object PSObject -Property $RowDetails
- }
- }
-
- }
- }
-
- $myFileName = [Environment]::GetFolderPath("Desktop") + "\workflowList.csv"
- $results | Select-Object "List Name", "Workflow Name", "Running Instances", "Created On","Modified On","Parent Web", "Task List","History List" | export-csv -Path $myFileName -NoTypeInformation
-
- }
-
- catch
- {
- $e = $_.Exception
- $line = $_.InvocationInfo.ScriptLineNumber
- $msg = $e.Message
- Write-Host –ForegroundColor Red "Caught Exception: $e at $line"
- Write-Host $msg
- Write-Host "Something went wrong"
- }
-
- Write-Host " === === === === === Completed! === === === === === === == "
Illustration
The code iterates through all the child webs within a site collection. It then flags the on the WorkflowAssociations property of the list, as shown in the line below,
- if ($list.WorkflowAssociations -eq $true)
Once it gets inside that loop, it then collects all the appropriate list identifiers as well as the necessary workflow details. It also captures the task list and the history list of the workflows, along with the count of running instances.
Usage
- In the script, just change the site collection URL and run it.
- The output CSV file will be generated in the desktop with the name workflowList.csv