Powershell to get last run date of SharePoint 2010 workflow

MeShare 21 Reputation points

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,889 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,449 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Limitless Technology 39,506 Reputation points

    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"

    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

    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

    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.


    0 comments No comments