Get SharePoint Workflow Queue Count
This script will output the Workflow Queue count for each queue. This can be used for tuning the SharePoint Workflow Engine.
#-------------------------------------------------------------------------------------------
# Name: Get-SPFarmWorkflowQueue.ps1 V1
# Description: This script provide the number of Workflow SPWorkItems for each db
# Usage: run .\Get-SPFarmWorkflowQueue.ps1
# By: Ivan Josipovic, softlanding.ca
#-------------------------------------------------------------------------------------------
#WorkflowTaskType bdeadf08-c265-11d0-bced-00a0c90ab50f
#WorkItemHostType bdeadf09-c265-11d0-bced-00a0c90ab50f
#WorkflowFailover bdeadf17-c265-11d0-bced-00a0c90ab50f
#WorkflowTimerType bdeade79-c265-11d0-bced-00a0c90ab50f
#WorkflowAutoCleanType bdeadf18-c265-11d0-bced-00a0c90ab50f
Function Get-WorkItems ([Microsoft.SharePoint.Administration.SPContentDatabase]$Database, [Guid]$Guid){
$WorkItems = New-Object Microsoft.SharePoint.SPWorkItemCollection($Database,[Guid]$Guid);
foreach ($WorkItem in $WorkItems){
$WorkItems.UpdateWorkItem($($WorkItem.Id),(Get-Date).ToUniversalTime(),$null,$null);
}
return $($WorkItems.Count)
}
Function Get-SPFarmWorkflowQueue(){
Foreach ($DB in $(Get-SPContentDatabase)){
if($((Get-SPFarm).BuildVersion.Major) -eq 15){
#SP2013 has a method for getting the workitem count
$WorkflowTaskType = [Microsoft.SharePoint.SPWorkItemCollection]::GetWorkItemCount($DB, [Guid]"bdeadf08-c265-11d0-bced-00a0c90ab50f");
$WorkItemHostType = [Microsoft.SharePoint.SPWorkItemCollection]::GetWorkItemCount($DB, [Guid]"bdeadf09-c265-11d0-bced-00a0c90ab50f");
$WorkflowFailover = [Microsoft.SharePoint.SPWorkItemCollection]::GetWorkItemCount($DB, [Guid]"bdeadf17-c265-11d0-bced-00a0c90ab50f");
$WorkflowTimerType = [Microsoft.SharePoint.SPWorkItemCollection]::GetWorkItemCount($DB, [Guid]"bdeade79-c265-11d0-bced-00a0c90ab50f");
$WorkflowAutoCleanType = [Microsoft.SharePoint.SPWorkItemCollection]::GetWorkItemCount($DB, [Guid]"bdeadf18-c265-11d0-bced-00a0c90ab50f");
}else{
#SP2010
$WorkflowTaskType = Get-WorkItems $DB "bdeadf08-c265-11d0-bced-00a0c90ab50f";
$WorkItemHostType = Get-WorkItems $DB "bdeadf09-c265-11d0-bced-00a0c90ab50f";
$WorkflowFailover = Get-WorkItems $DB "bdeadf17-c265-11d0-bced-00a0c90ab50f";
$WorkflowTimerType = Get-WorkItems $DB "bdeade79-c265-11d0-bced-00a0c90ab50f";
$WorkflowAutoCleanType = Get-WorkItems $DB "bdeadf18-c265-11d0-bced-00a0c90ab50f";
}
if ($WorkflowTaskType -gt 0){
Write-Host "$($DB.Name) WorkflowTaskType Count: $WorkflowTaskType";
}
if ($WorkItemHostType -gt 0){
Write-Host "$($DB.Name) WorkItemHostType Count: $WorkItemHostType";
}
if ($WorkflowFailover -gt 0){
Write-Host "$($DB.Name) WorkflowFailover Count: $WorkflowFailover";
}
if ($WorkflowTimerType -gt 0){
Write-Host "$($DB.Name) WorkflowTimerType Count: $WorkflowTimerType";
}
if ($WorkflowAutoCleanType -gt 0){
Write-Host "$($DB.Name) WorkflowAutoCleanType Count: $WorkflowAutoCleanType";
}
}
}
While ($True){
Get-SPFarmWorkflowQueue;
Start-Sleep -Seconds 1;
}
The SharePoint Workflow engine has a number of tuning options. However, there are no easy ways to find out how taxed the workflow engine is. This script will iterate through all of the content databases and return the count of each workflow queue. This information is very useful for tuning.
Comments
Post a Comment