Skip to main content
added 1050 characters in body
Source Link
Christoffer
  • 9.9k
  • 3
  • 37
  • 53

Update

Corrected the double use of the variable $wf and added MickB suggestions to get the name property.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$sub = $wfm.GetWorkflowSubscriptionService()
$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

        write-host "Workflow Title: $wfName Status: $wfStatus ListItem: $wfListItem"
    }

}

Update

Corrected the double use of the variable $wf and added MickB suggestions to get the name property.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$sub = $wfm.GetWorkflowSubscriptionService()
$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

        write-host "Workflow Title: $wfName Status: $wfStatus ListItem: $wfListItem"
    }

}
added 18 characters in body
Source Link
Christoffer
  • 9.9k
  • 3
  • 37
  • 53

For the SharePoint 2010 workflows (or 2010 workflows in a 2013 environment) you can run this.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$wf = @()

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

foreach ($wf in $list.WorkflowAssociations)
{
    $wfAssociations += $($wf)
}

if ($wfAssociations.count -ge 1)
{
    foreach ($item in $list.Items)
    {
        foreach($workflow in $item.workflows)
        {
            $wfName = $wf.Name
            $wfStatus = $workflow.InternalState
            $wfListItem = $workflow.ItemName

            write-host "Workflow Title: $wfName Status: $wfStatus ListItem: $wfListItem"
        }
    }
}

For a 2013 workflow, you have to do it little difference because you have to access the workflows from the workflow manager.

I did some tests but i can't manage to pick up the title, only the GUID.

You might be able to figure it out, or the ID is maybe enough for you. I need to get back to work. :)

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$sub = $wfm.GetWorkflowSubscriptionService()
$wf = $sub.EnumerateSubscriptionsByList($list.ID)
$wfis=$wfm.GetWorkflowInstanceService()

foreach ($item in $list.Items)
{
    $workflowInstances=$wfis.EnumerateInstancesForListItem($list.ID,$item.ID)

    foreach($wf in $workflowInstances) 
    {
        #$wfName = $wf.Name **<---- Won't work here.**
        $wfID= $wf.ID
        $wfStatus = $wf.Status
        $wfListItem = $item.Name

        write-host "Workflow Title: $wfID Status: $wfStatus ListItem: $wfListItem"
    }

}

For the SharePoint 2010 workflows (or 2010 workflows in a 2013 environment) you can run this.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$wf = @()

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

foreach ($wf in $list.WorkflowAssociations)
{
    $wfAssociations += $($wf)
}

if ($wfAssociations.count -ge 1)
{
    foreach ($item in $list.Items)
    {
        foreach($workflow in $item.workflows)
        {
            $wfName = $wf.Name
            $wfStatus = $workflow.InternalState
            $wfListItem = $workflow.ItemName

            write-host "Workflow Title: $wfName Status: $wfStatus ListItem: $wfListItem"
        }
    }
}

For a 2013 workflow, you have to do it little difference because you have to access the workflows from the workflow manager.

I did some tests but i can't manage to pick up the title, only the GUID.

You might be able to figure it out, or the ID is enough for you. I need to work. :)

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$sub = $wfm.GetWorkflowSubscriptionService()
$wf = $sub.EnumerateSubscriptionsByList($list.ID)
$wfis=$wfm.GetWorkflowInstanceService()

foreach ($item in $list.Items)
{
    $workflowInstances=$wfis.EnumerateInstancesForListItem($list.ID,$item.ID)

    foreach($wf in $workflowInstances) 
    {
        #$wfName = $wf.Name **<---- Won't work here.**
        $wfID= $wf.ID
        $wfStatus = $wf.Status
        $wfListItem = $item.Name

        write-host "Workflow Title: $wfID Status: $wfStatus ListItem: $wfListItem"
    }

}

For the SharePoint 2010 workflows (or 2010 workflows in a 2013 environment) you can run this.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$wf = @()

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

foreach ($wf in $list.WorkflowAssociations)
{
    $wfAssociations += $($wf)
}

if ($wfAssociations.count -ge 1)
{
    foreach ($item in $list.Items)
    {
        foreach($workflow in $item.workflows)
        {
            $wfName = $wf.Name
            $wfStatus = $workflow.InternalState
            $wfListItem = $workflow.ItemName

            write-host "Workflow Title: $wfName Status: $wfStatus ListItem: $wfListItem"
        }
    }
}

For a 2013 workflow, you have to do it little difference because you have to access the workflows from the workflow manager.

I did some tests but i can't manage to pick up the title, only the GUID.

You might be able to figure it out, or the ID is maybe enough for you. I need to get back to work. :)

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$sub = $wfm.GetWorkflowSubscriptionService()
$wf = $sub.EnumerateSubscriptionsByList($list.ID)
$wfis=$wfm.GetWorkflowInstanceService()

foreach ($item in $list.Items)
{
    $workflowInstances=$wfis.EnumerateInstancesForListItem($list.ID,$item.ID)

    foreach($wf in $workflowInstances) 
    {
        #$wfName = $wf.Name **<---- Won't work here.**
        $wfID= $wf.ID
        $wfStatus = $wf.Status
        $wfListItem = $item.Name

        write-host "Workflow Title: $wfID Status: $wfStatus ListItem: $wfListItem"
    }

}
Source Link
Christoffer
  • 9.9k
  • 3
  • 37
  • 53

For the SharePoint 2010 workflows (or 2010 workflows in a 2013 environment) you can run this.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$wf = @()

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

foreach ($wf in $list.WorkflowAssociations)
{
    $wfAssociations += $($wf)
}

if ($wfAssociations.count -ge 1)
{
    foreach ($item in $list.Items)
    {
        foreach($workflow in $item.workflows)
        {
            $wfName = $wf.Name
            $wfStatus = $workflow.InternalState
            $wfListItem = $workflow.ItemName

            write-host "Workflow Title: $wfName Status: $wfStatus ListItem: $wfListItem"
        }
    }
}

For a 2013 workflow, you have to do it little difference because you have to access the workflows from the workflow manager.

I did some tests but i can't manage to pick up the title, only the GUID.

You might be able to figure it out, or the ID is enough for you. I need to work. :)

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$web = get-spweb -Identity https://spwebUrl
$list = $web.Lists["ListName"]

$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$sub = $wfm.GetWorkflowSubscriptionService()
$wf = $sub.EnumerateSubscriptionsByList($list.ID)
$wfis=$wfm.GetWorkflowInstanceService()

foreach ($item in $list.Items)
{
    $workflowInstances=$wfis.EnumerateInstancesForListItem($list.ID,$item.ID)

    foreach($wf in $workflowInstances) 
    {
        #$wfName = $wf.Name **<---- Won't work here.**
        $wfID= $wf.ID
        $wfStatus = $wf.Status
        $wfListItem = $item.Name

        write-host "Workflow Title: $wfID Status: $wfStatus ListItem: $wfListItem"
    }

}