aaron.labiosa@nintex.com

How to locate Nintex Workflows via PowerShell

Blog Post created by aaron.labiosa@nintex.com Champion on Dec 12, 2014

Products: Nintex Workflow 2013, Nintex Workflow 2010

 

We have often seen the requirement to be able to report on how many Nintex Workflows are in an environment and where they are.

 

Using this PowerShell script you can generate a report of how many workflows are found on each site/subsite/list in a SharePoint environment.

 

Note: This script only targets the Nintex Configuration Database. Update: Script now targets all Nintex databases.

 

Run the below (attached as well as a *.txt file for your convenience) PowerShell script (PowerShell ISE works well) from a SharePoint Server:

PowerShell Script
  1. Add-PSSnapin Microsoft.SharePoint.PowerShell
  2. [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  3. [void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Workflow")
  4. #[void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Workflow.SupportConsole")
  5. [void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Workflow.Administration")
  6. [void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Forms.SharePoint.Administration")
  7. $cmd = New-Object -TypeName System.Data.SqlClient.SqlCommand
  8. $cmd.CommandType = [System.Data.CommandType]::Text
  9. $cmd.CommandText = "SELECT
  10.                COUNT (DISTINCT workflowid)as NumberofWorkflows,
  11.                SiteID,
  12.                WebID,
  13.                listid
  14. FROM WorkflowInstance I inner join WorkflowProgress P
  15.                ON I.InstanceID = P.InstanceID
  16. GROUP BY GROUPING SETS((i.siteid, i.webid, i.listid), ());"
  17. $indexes = @()
  18. foreach ($database in [Nintex.Workflow.Administration.ConfigurationDatabase]::GetConfigurationDatabase().ContentDatabases)
  19. {
  20. $reader = $database.ExecuteReader($cmd)
  21. while($reader.Read())
  22. {
  23. $row = New-Object System.Object
  24. if(![string]::IsNullOrEmpty($reader["SiteID"])){
  25. $Site = $(Get-SPSite -identity $reader["SiteID"])
  26. }
  27. if(![string]::IsNullOrEmpty($reader["WebID"])){
  28. $SubSite = $Site.Allwebs[[Guid]"$($reader["WebID"])"]
  29. }
  30. if(![string]::IsNullOrEmpty($reader["ListID"])){
  31. $List = $SubSite.Lists[[Guid]"$($reader["ListID"])"]
  32. }
  33. $row | Add-Member -MemberType NoteProperty -Name "Number Of Workflows" -Value $reader["NumberofWorkflows"]
  34. $row | Add-Member -MemberType NoteProperty -Name "Site Collection" -Value $Site.Url
  35. $row | Add-Member -MemberType NoteProperty -Name "Subsite" -Value $SubSite
  36. $row | Add-Member -MemberType NoteProperty -Name "List" -Value $List.title
  37. $indexes += $row
  38. }
  39. }
  40. $indexes

Attachments

Outcomes