Get all Workflows from a SharePoint 2010 Application using PowerShell

I needed a way to programmatically get all of the workflows from all site collections and webs. PowerShell looks to be the best answer.

This script returns all items in all sites, webs and lists with workflow attached from the application level. It then outputs a file with a pipe separated list of everything.

$url = "http://chaosweb"
$filePath = "D:\workflow_items.txt"

$rootSite = New-Object Microsoft.SharePoint.SPSite($url)
$spWebApp = $rootSite.WebApplication

$ListItems = @()

foreach($site in $spWebApp.Sites)
{
    $spWebs = $site.AllWebs
    foreach($spWeb in $spWebs)
    {
        for($i = 0; $i -lt $spWeb.Lists.Count; $i++)
        {
            $spList = $spweb.Lists[$i]
            $assoc = $spList.WorkflowAssociations 

            if($assoc -ne $null)
            {
                foreach($item in $spList.Items)
                {
                    $ListItems += "$($site.URL) | $($spWeb.Name) | $($spList.Title) | $($item.Name)"
                }
            }
        }
    }
    $spWeb.Dispose()
}

$ListItems | out-file -filepath $filePath

2 thoughts on “Get all Workflows from a SharePoint 2010 Application using PowerShell”

  1. Thanks for this script. Why did you use the variable $workflowBase? I don't see it used elsewhere.

    Soumya

Leave a Comment

Your email address will not be published.