Get running instances of SharePoint 2010 workflow in SharePoint online

Tanmoy Das 806 Reputation points
2020-09-08T04:09:02.077+00:00

Hi Guys,

Is there a way I can list out the SharePoint 2010 workflows which have running instances in the list and libraries in SharePoint online.

Microsoft 365 and Office SharePoint For business Windows
{count} votes

2 answers

Sort by: Most helpful
  1. Emily Du-MSFT 51,836 Reputation points Microsoft External Staff
    2020-09-08T08:05:29.157+00:00

    You could try below script.

    #Load SharePoint CSOM Assemblies  
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.WorkflowServices.dll"  
      
    #Function to Get workflows in a site  
    Function Get-SPOWorkflowInventory($SiteURL, $CSVPath)  
    {  
        Try{  
            $WorkflowInventory = @()  
            #Setup the context  
            $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)  
            $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)  
           
            #Get the Web and its Subsites  
            $Web = $Ctx.Web  
            $Ctx.Load($Web)  
            $Ctx.Load($Web.Webs)  
            $Lists = $Web.Lists  
            $Ctx.Load($Lists)  
            $Ctx.ExecuteQuery()      
       
            Write-host -f Yellow "Searching Workflows in Site: $SiteURL"  
            #Loop through each list and get all workflows sharepoint online powershell  
            ForEach($List in $Lists)  
            {  
                #Get SharePoint 2010 Workflows Associated  
                $WorkflowAssociations = $List.WorkflowAssociations  
                $Ctx.Load($WorkflowAssociations)  
                $Ctx.ExecuteQuery()  
                ForEach($Association in $WorkflowAssociations | Where {$_.Name -notlike "*Previous Version*"})  
                {  
                    $WorkflowData = New-Object PSObject  
                    $WorkflowData | Add-Member NoteProperty WorkflowName($Association.Name)  
                    $WorkflowData | Add-Member NoteProperty SiteURL($Web.Url)  
                    $WorkflowData | Add-Member NoteProperty ListName($List.Title)  
                    Write-host -f Green "`t Found Workflow '$($Association.Name)' in list '$($List.Title)'"  
                    $WorkflowInventory+=$WorkflowData  
                }  
            }  
            #Export Workflow data to CSV File  
            If($WorkflowInventory) { $WorkflowInventory | Export-CSV -LiteralPath $CSVPath -NoTypeInformation -Append}  
       
            #Process Subsites  
            Foreach($Subweb in $Web.Webs)  
            {  
                Get-SPOWorkflowInventory -SiteURL $Subweb.url  
            }  
        }  
        Catch {  
        Write-host -f Red "Error:" $_.Exception.Message  
        }  
    }  
       
    #Set Parameters  
    $SiteURL="site collection URL "  
    $CSVPath = "your local drive"  
       
    #Remove the CSV file if exists  
    If(Test-Path $CSVPath) { Remove-Item $CSVPath}  
       
    #Get Credentials to connect  
    $Cred= Get-Credential  
       
    #Call the function to get workflow inventory  
    Get-SPOWorkflowInventory $SiteURL $CSVPath  
    

    Here're some references for you.
    Get SharePoint Online workflows by using PowerShell CSOM
    SharePoint Online get workflow inventory using PowerShell


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Chilly 116 Reputation points
    2021-05-24T18:29:35.75+00:00

    It appears that this script identifies all the workflows in a list, but it does not identify the specific running instances.

    Is there a way to identify the specific running instances?

    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.