Enumerating Workflows Associations across your Farm in MOSS 2007

I have a client that is currently migrating from MOSS 2007 to SharePoint 2010 just in time for SharePoint 2013. 🙂

 
They have chosen to migrate manually because a lot of what was built in MOSS was never used.  They also leveraged the wild, wild, west method of planning their deployment.
 
Leveraging the opportunity to restructure they asked me if there was a way to see all workflows (OOTB and Designer) that are being used throughout the entire farm.  Given my love for PowerShell, I thought it was time to dust off my old 2007 virtual machines and SDKs to see what I could come up with.
 
I hate to reinvent the wheel so I did a quick internet search where I found this blog post – Getting a List of all Workflow Associations – Thanks JShidell!
 
This blog gave me a great start.  The only thing missing was the ability to iterate through all web applications.  If the script did this it could be environment agnostic and you wouldn’t have to provide any URLs.
 
Here is the script that I came up with…
 
#Load SharePoint 2007 Assemblies
[void][system.reflection.assembly]::load("Microsoft.sharepoint, version=12.0.0.0, culture=neutral, publickeytoken=71e9bce111e9429c")
 
# Script variables
$date = get-date -format "yyyy-MM-dd_HH-mm"
 
# Workflow Variables
$WFExport = "c:\\scripts\\exports\\Workflows_$date.csv"
 
# Main Body
# Creating Export File
out-file -filepath $WFExport -inputobject "|"
 
# Looping through Web Applications, Site Collections, Webs and Lists
$Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$Service = $Farm.Services | Where{$_.TypeName -eq "Windows SharePoint Services Web Application"}
$WebApps = $Service.WebApplications
Foreach ($WebApp in $WebApps)
{
    $Sites = $WebApp.Sites
    Foreach ($Site in $Sites)
    {
        $Webs = $Site.AllWebs
        Foreach ($Web in $Webs)
        {
             $Lists = $Web.Lists
            Foreach ($List in $Lists)
            {
                $Workflows = $List.WorkflowAssociations
                Foreach ($Workflow in $Workflows)
                {
                    If ($Workflow.Name -notlike "Previous Version*")
                    {
                        out-file -filepath $WFExport -append -inputobject($Workflow.Name + "|" + $Workflow.InternalName + "|"+ $WebApp.Name + "|" + $Site.RootWeb.Title + "|" + $Web.Title + "|" + $Web.URL + "|" + $List.Title + "|")
                    }
                }
            }
        }
    }
}
 
 
The end result is a CSV file that you can pull into Excel and format as a report.  Enjoy!

 

Leave a Reply