Saturday, October 5, 2019

List of Running Workflows in SharePoint Site Collection using PowerShell

Clear-Host
$site=Get-SPSite("http://2010.ajtech.com");

#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 c:\workflows.csv
"Workflow Count " + $workflowcount >> c:\workflows.csv

$site.Dispose()

No comments:

Post a Comment