PowerShell scripts for workflows

links to good PowerShell scripts for workflows

SP2007

PowerShell Script To Find Instances Of Running SharePoint Workflow

$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)”
}
}
}

Get  list item workflow instance ID

in this example I am selecting a specific item from a list and presenting the item workflow instance id by traversing through workflows associated with that item:

foreach ($listItem in $list.items){
$recordCounter ++
if ($listItem.Id  -eq 529){
Write-Host $listItem.Name ” | ” $listItem.Id ” | ” $listItem[“WorkflowInstanceID”] ” | WFIID-” $listItem[“InstanceID”] ” | WFS-” $listItem[“WorkflowStatus”] ” | ” $listItem[“WorkflowVersion”]
if ($listItem.Workflows){
foreach($workflow in $listItem.Workflows){
Write-Host $workflow.InstanceId
}
}
}

}
Get the workflow instance id for a task item

$site = New-Object Microsoft.SharePoint.SPSite(“YourSiteUrl”)
$web = $site.openweb()
$lists = $web.Lists
$listTasks = $web.Lists[“YourListName”]
$item = $listTasks.Items[500]  # picking item 500 from the items array
Write-Host $item.id ” | ” $item.name ” | wflid” $item[“WorkflowInstanceID”]  ” | ” $item[“WorkflowVersion”] ” | ” $item[“_ModerationStatus”]

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *