Powershell to get last run date of SharePoint 2010 workflow

MeShare 21 Reputation points
2021-09-16T15:21:59.597+00:00

Hi All,

I want to create a PowerShell script to get last run date of my SharePoint 2010 sites list workflows.
I am able to get the last modified date of workflows but not the last run date .

Please help .

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,952 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,537 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Limitless Technology 39,651 Reputation points
    2021-09-16T19:48:00.083+00:00

    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,

    0 comments No comments

  2. MeShare 21 Reputation points
    2021-09-17T05:30:27.84+00:00

    Hi @Limitless Technology ,

    Thanks for the response. I will try and let you know the result.

    Please suggest if this script will give the last run date of workflow or last modified date of the workflow?

    I am only looking for last run date of my workflows so that I can distinguish active and non active workflows in my SharePoint 2010 farm.

    Thanks .

    0 comments No comments

  3. Stephen Curry 1 Reputation point
    2022-06-15T14:33:00.293+00:00

    hi @Limitless Technology & @MeShare

    Did the above script work for you? I have a need to get all workflows within a SharePoint 2013 environment along with their last run date.

    Thanks,

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.