Get all workflows in all sites and lists

Summary: This blog post describes how to get all workflows in all sites and lists in SharePoint 2010 and SharePoint 2013.

From an administrator point of view, it can be hard to keep track of all workflows used in your SharePoint 2010 environment. To make things a little easier, I created a script that will tell you the names of all workflows that are used within your SharePoint farm.

Please make sure that the user running this script has at least read permissions to the webs you are trying to check.

*UPDATE* Version 1.1 *UPDATE*
– Increased performance by using the .allwebs property instead of Get-SPWeb
– Changed the script so you can run the script as any other PowerShell script

param ([boolean] $writeToFile = $true)
#List all workflows in farm
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #If boolean is set to true, you can specify an outputlocation, to save to textfile.

if($writeToFile -eq $true)
{
$outputPath = Read-Host "Outputpath (e.g. C:directoryfilename.txt)"
}
#Counter variables
$webcount = 0
$listcount = 0
$associationcount = 0

#Grab all webs
Get-SPSite -Limit All | % {$webs += $_.Allwebs}
if($webs.count -ge 1)
{
foreach($web in $webs)
{
#Grab all lists in the current web
$lists = $web.Lists
foreach($list in $lists)
{
$associations = @()
#Get all workflows that are associated with the current list
foreach($listassociation in $list.WorkflowAssociations)
{
$associations += $($listassociation.name)
}
$listcount +=1
if($associations.count -ge 1)
{
Write-Host "Website"$web.url -ForegroundColor Green
Write-Host "  List:"$list.Title -ForegroundColor Yellow
foreach($association in $associations){Write-Host "   -"$association}

if($WriteToFile -eq $true)
{
Add-Content -Path $outputPath -Value "Website $($web.url)"
Add-Content -Path $outputPath -Value "  List: $($list.Title)"
foreach($association in $associations){Add-Content -Path $outputPath -Value "   -$association"}
Add-Content -Path $outputPath -Value "`n"
}
}
}
$webcount +=1
$web.Dispose()
}
#Show total counter for checked webs & lists
Write-Host "Amount of webs checked:"$webcount
Write-Host "Amount of lists checked:"$listcount
$webcount = "0"
}
else
{
Write-Host "No webs retrieved, please check your permissions" -ForegroundColor Red -BackgroundColor Black
$webcount = "0"
}

As you can see the script has only 1 parameter, $writeToFile. Without specifying this parameter, the script will ask for an output location, to save the results. If you do not want the script to save the output, you can call the function like this:
.Get-SPWorkflow -writeToFile $false

I have tested this script on several environments, the largest having 4815 lists checked.

For privacy reasons, I can only show the output from my own testing environment, this is a possible outcome:

Get all workflows in all sites and lists