The following script will return all Workflows currently associated within your SharePoint 2007 or SharePoint 2010 farm using PowerShell and output it to a CSV file. It returns the URL of the site, Title of the list, Title of the workflow, and the number of currently running instances.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null $outputFile = Read-Host "Filename and location (i.e. C:\output.txt)" $farm = [Microsoft.SharePoint.Administration.SPFarm]::local $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]} $webapps = @() $outputHeader = "Url;List;Workflow;Running Instances" > $outputFile foreach ($websvc in $websvcs) { foreach ($webapp in $websvc.WebApplications) { foreach ($site in $webapp.Sites) { foreach ($web in $site.AllWebs) { foreach ($List in $web.Lists) { foreach ($workflow in $List.WorkflowAssociations) { $output = $web.Url + ";" + $List.Title + ";" + $workflow.Name + ";" + $workflow.RunningInstances Write-Output $output >> $outputFile }} } } } } $Web.Dispose(); $site.Dispose();
It can also be downloaded from my Google Drive here: CheckWorkflowsInFarm.zip
Output Example:
Url;List;Workflow;Running Instances
http://intranet;Report a Problem or New Request;Notification Workflow for Bug List (Previous Version:4/13/2011 3:01:15 PM);0
http://intranet;Report a Problem or New Request;Notification Workflow for Bug List;0
http://intranet;Report a Problem or New Request;Notification Workflow for Bug List (Previous Version:4/13/2011 3:04:13 PM);0
http://intranet/contracts;PDF Doc Library;Send to Sales;0
http://intranet/contracts;PDF Doc Library;Send to Sales (Previous Version:6/4/2010 5:33:55 PM);0
http://intranet/contracts;Doc Library;DOC Approval (Previous Version:6/29/2010 3:55:22 PM);1
http://intranet/contracts;Doc Library;DOC Approval;0
http://intranet/contracts;Doc Library;DOC Approval (Previous Version:6/29/2010 3:49:51 PM);0
http://intranet/contracts;Doc Library;DOC Approval (Previous Version:6/29/2010 3:37:48 PM);0
http://intranet/contracts;Doc Library;DOC Approval (Previous Version:6/29/2010 11:18:26 AM);0

Great script, but i needed avoid "previus version" and launch it only for one site collection because of memory so I used this:
ReplyDelete#Load SharePoint 2007 Assemblies
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null
$siteurl="http://your.site.com"
$site=new-object Microsoft.SharePoint.SPSite($siteurl)
#Initialize Workflow Count variable
$workflowcount = 0
#Foreach loop to loop through all webs, and lists with workflow associations, and exclude workflows that have previous versions and write findings to .csv file.
function Get-Workflows()
{
foreach($web in $site.AllWebs)
{
foreach($list in $web.Lists)
{
foreach($wf in $list.WorkflowAssociations)
{
if ($wf.Name -notlike "*Previous Version*")
{
$hash = @{"[URL]"=$web.Url;"[List Name]"=$list.Title;"[Workflow]"=$wf.Name}
New-Object PSObject -Property $hash | Sort-Object
}
}
}
}
}
foreach($web in $site.AllWebs)
{
foreach($list in $web.Lists)
{
foreach($wf in $list.WorkflowAssociations)
{
if ($wf.Name -notlike "*Previous Version*")
{
$workflowcount += 1
}
}
}
}
Get-Workflows | Export-csv E:\workflows.csv
"Workflow Count " + $workflowcount >> E:\workflows.csv
$site.Dispose()
Hi Jeff:
ReplyDeleteDavid Tobey from Nintex here. I just wanted to leave a note to say how much I like this script you've built. Easy to follow and extremely versatile, considering you can drop a CSV file right into Excel for sorting. Nice work!