In the SharePoint list, each item has a workflow of a particular version. How do I display all the workflows and their individual count from that SharePoint list using PowerShell.
1 Answer
the below script could be a starting point. in that script you provide the workflow name, then it will check which list item is associate and running.
$workflowNameToCheck = "My Sample Workflow"
$url = "http://SharePointDemo"
$spSite = new-object Microsoft.SharePoint.SPSite($url)
$spWeb = $spSite.OpenWeb()
$workflowBase = $spweb.WorkflowTemplates | where {$_.Name -eq $workflowNameToCheck}
$spWeb.Dispose()
foreach($spWeb in $spSite.AllWebs)
{
for($i = 0; $i -lt $spWeb.Lists.Count; $i++)
{
$spList = $spweb.Lists[$i]
$assoc = $spList.WorkflowAssociations | where {$_.BaseId -eq $workflowBase.Id.ToString() `
-and $_.RunningInstances -gt 0}
if($assoc -ne $null)
{
foreach($item in $spList.Items)
{
if(($item.Workflows | where {$_.InternalState -eq "Running"}) -ne $null)
{
write-output "$($spWeb.Name) | $($spList.Title) | $($item.Name)"
}
}
}
}
$spWeb.Dispose()
}
$spSite.Dispose()
you can read more here: PowerShell Script To Find Instances Of Running SharePoint Workflow
Also check this: How to retrieve workflows in powershell?
-
I do not want individual workflow of each item in the list. I wanted all the different workflows that are used by the items of the list and the count of each workflow used by items in the list. Commented Dec 4, 2018 at 4:35