cancel
Showing results for 
Search instead for 
Did you mean: 

How to locate Nintex Workflows via PowerShell

Workflow Hero
17 1 4,195

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
1 Comment
Workflow Hero

Do I need to modify anything within this script for it to work with my SharePoint site?  I am getting the following errors when I run the script from the application server:

Exception calling "ExecuteReader" with "1" argument(s): "Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding."
At C:\Admin\Scripts\locate-workflows\locate-workflows.ps1:27 char:34
+ $reader = $database.ExecuteReader <<<< ($cmd)
    + CategoryInfo          : NotSpecified: (Smiley Happy [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression.
At C:\Admin\Scripts\locate-workflows\locate-workflows.ps1:29 char:19
+ while($reader.Read <<<< ())
    + CategoryInfo          : InvalidOperation: (ReadSmiley Frustratedtring) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull