Introduction
Many times we have a requirement to list out all workflows which have been created in SharePoint Online in order to rewrite/scrap useless workflows or because of some other reason.
You can modify this workflow based on your requirement if you want to have more details about the list/site/item.
The current workflow performs the below actions,
  1. Gets all workflows from all lists and libraries from SharePoint Online site collection.
  2. Exports the workflow data into a CSV file
References
You need to add the below 3 references in your ps1 file,
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"
Later you need to update only with your site collection URL at:
$SiteURL="Your SharePoint Online Site Collection URL"
Complete Script
  1. #Start Code
  2. #Load SharePoint CSOM Assemblies
  3. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
  4. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  5. Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.WorkflowServices.dll"
  6. #Function to Get workflows in a site
  7. #Set Parameters
  8. $SiteURL="Your Site URL"
  9. $CSVPath = "D:\Project\WorkflowInventoryGCP.csv"
  10. Function GetNintexForm(){
  11. $SiteUrl = "Site URL"
  12. $UserName = "User Name"
  13. #Bind to site collection
  14. $SecurePassword = ConvertTo-SecureString "Password" -AsPlainText -Force
  15. $ClientContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
  16. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
  17. $ClientContext.Credentials = $credentials
  18. $ClientContext.ExecuteQuery()
  19. # Create WorkflowServicesManager instance
  20. $WorkflowServicesManager = New-Object Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager($ClientContext, $ClientContext.Web)
  21. # Connect to WorkflowSubscriptionService
  22. $WorkflowSubscriptionService = $WorkflowServicesManager.GetWorkflowSubscriptionService()
  23. # Connect WorkflowInstanceService instance
  24. $WorkflowInstanceService = $WorkflowServicesManager.GetWorkflowInstanceService()
  25. $ClientContext.Load($WorkflowServicesManager)
  26. $ClientContext.Load($WorkflowSubscriptionService)
  27. $ClientContext.Load($WorkflowInstanceService)
  28. $ClientContext.ExecuteQuery()
  29. # Get Site Workflows
  30. $SiteWorkflows = $WorkflowSubscriptionService.EnumerateSubscriptions()
  31. $ClientContext.Load($SiteWorkflows)
  32. $ClientContext.ExecuteQuery()
  33. $SiteWorkflows | Select Id, Name, StatusFieldName | FT -AutoSize
  34. If($SiteWorkflows) { $SiteWorkflows | Export-CSV -LiteralPath $CSVformPath -NoTypeInformation -Append}
  35. # Define Site Workflow
  36. # $SiteWorkflowID = 'mysiteworkflowid'
  37. # $SiteWorkflow = $WorkflowSubscriptionService.GetSubscription($SiteWorkflowID)
  38. # $ClientContext.Load($SiteWorkflow)
  39. # $ClientContext.ExecuteQuery()
  40. # Prepare Start Workflow Payload
  41. $Dict = New-Object 'System.Collections.Generic.Dictionary[System.String,System.Object]'
  42. # Loop Start Workflow
  43. For ($j=0; $j -lt 10; $j++){
  44. $Action = $WorkflowInstanceService.StartWorkflow($SiteWorkflow, $Dict)
  45. #$ClientContext.ExecuteQuery()
  46. # Get Workflow Status
  47. #$WorkflowInstance = $Action.Value
  48. #$WorkflowStatus = $WorkflowInstanceService.GetInstance($Action.Value)
  49. #$ClientContext.Load($WorkflowStatus)
  50. #$ClientContext.ExecuteQuery()
  51. #Write-Host $Action.Value $WorkflowStatus.Status
  52. }
  53. }
  54. #End
  55. #Remove the CSV file if exists
  56. If(Test-Path $CSVPath) { Remove-Item $CSVPath}
  57. #Get Credentials to connect
  58. $Cred= Get-Credential
  59. #Call the function to get workflow inventory
  60. GetNintexForm
  61. #End Code
The output of the script will be:

Also, I have uploaded a ps file along with this, just change the URL to yours and start using it.
Happing Coding!!