Hello @vinaysingh-3672
Please try this script. The scripts below will check all the list/library with the site collection and output all workflow status and information:
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$web = Get-SPWeb -Identity https://spwebUrl
$wfm = New-Object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$sub = $wfm.GetWorkflowSubscriptionService()
foreach ($list in $web.Lists)
{
$wfs = $sub.EnumerateSubscriptionsByList($list.ID)
$wfis = $wfm.GetWorkflowInstanceService()
foreach ($item in $list.Items)
{
$workflowInstances = $wfis.EnumerateInstancesForListItem($list.ID, $item.ID)
foreach ($wf in $workflowInstances)
{
$wfName = $wfs | ?{$_.Id -eq $wf.WorkflowSubscriptionId} | select -ExpandProperty Name
$wfID = $wf.ID
$wfStatus = $wf.Status
$wfListItem = $item.Name
$WFLastUpDateTime = $wf.LastUpdated.ToLocalTime()
$modifiedDateTime = Get-Date $WFLastUpDateTime
if ($modifiedDateTime -gt (get-date).AddHours(-1))
{
#write-host "List name: $list, Workflow Title: $wfName, ListItem Name: $wfListItem, WorkflowStatus: $wfStatus, last Workflow: $modifiedDateTime" -f yellow
Write-Output "List name: $list, Workflow Title: $wfName, ListItem Name: $wfListItem, WorkflowStatus: $wfStatus, last Workflow: $modifiedDateTime" | Add-Content "C:\output\workflowstatus.txt"
}
}
}
}
$web.Dispose()
Maybe would need some tuning for your environment but I think I can give you some perspective,
Best regards,