Get all workflows in all sites and lists


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:\directory\filename.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:

image

Advertisements

22 thoughts on “Get all workflows in all sites and lists

  1. If you run this script more than once, you might want to set the $web = $null, otherwise the number of webs/lists will never reset

  2. Did a version for sp 2007 powershell ever get written? I am trying to find something like this. Thank you.

  3. Does your script only identify the “out of the box” SharePoint workflows, or also C# and SharePoint Designer workflows?

  4. Here is the code modifications I did for this script. I have executed it against a 2007 Farm.

    param ([boolean] $writeToFile = $true)
    #List all workflows in farm
    #
    # SP2010 and above
    #Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

    #Load the DLL if it is not already for SharePoint 2007
    [void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

    #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:\directory\filename.txt)”
    }
    #Counter variables
    $webcount = 0
    $listcount = 0
    $associationcount = 0
    #Grab all webs

    #
    # To get all the site collections in SP2007
    $WebAppUrl = “http://your web application”
    $WebApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppUrl)
    #Loop through the sites (SPSite)
    foreach($site in $WebApp.Sites)
    {
    # AllWebs is a SPWebCollection for the specified SPSite
    # Gets the collection of all Web sites that are
    # contained within the site collection, including the
    # top-level site and its subsites.
    $webs += $site.AllWebs

    }

    #
    # How to get all the webs for SP2010 and above
    #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”
    }

  5. I have an SP 2010 question about your script, if you do not mind.

    I have executed this against my SP 2010 test farm, and it produces a series of lines.
    how would one tweak this script to mark an active workflow – that is, one which would allow new workflows to be run against it? I see many times where there are a series of previous versions of a workflow listed in the above script’s output. That is okay – but today I am not as interested in the older versions as I am the versions which might be able to generate a new instance.

    Another thing in which I am interested is being able to determine details of the workflow itself – in particular, the users or groups to which a task in the workflow might be assigned.
    How would one enhance the above script to provide that information?

    Thank you for this script – it is a useful model.

  6. Thanks for posting this – it works perfectly on our setup. I now trying to understand whet the script does exactly. Please can you tell me what this line does? $associations = @()

  7. Hello, I am new to powershell and all I need to do is list all workflows running across the SharePoint 2010 Farm and send it to a .csv with the site url, list/library, and the associated workflow. The script above appears like it may partially do the job, but I do not want to remove the workflow. Any help?

    • Hi Gordon,

      Thanks for taking your time to give some feedback. The script that is provided in the blog post (not the one in the comments) will only display the workflows, it will not remove any workflows.

      Regards,

      Nico

  8. Does this have to be ran on each web server or can it be ran on one server and just add the sites you want to get the workflows on? Example: I would like to run it on server A, but get the workflows for server b, c, d, e, f, etc. but run it on server A the entire time

    • ok, so how can I run it on a server but get all workflows within my farm? Currently, I’m only getting the workflows that the script is running on. I now want to get to all the workflows. Or does this have to run on the main server (central admin server) and then it gets all workflows? If so, I unable to run this on that server, I was hoping that I could run this on my developer server and get all workflows on the prod server.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s