How to locate Nintex Workflows via PowerShell

  • 13 December 2014
  • 2 replies
  • 108 views

Userlevel 7
Badge +10

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

2 replies

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:AdminScriptslocate-workflowslocate-workflows.ps1:27 char:34
+ $reader = $database.ExecuteReader <<<< ($cmd)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression.
At C:AdminScriptslocate-workflowslocate-workflows.ps1:29 char:19
+ while($reader.Read <<<< ())
    + CategoryInfo          : InvalidOperation: (Read:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

I'm getting this same error...what can be done to resolve to run this script?

Reply