Skip to main content

Products: Nintex Workflow 2013, Nintex Workflow 2010

 

This week a request came in for a way to activate Web Applications via PowerShell, below you will find a script that does exactly that. Each section of the Web Application sequence is segmented off into separate functions which are wrapped in try/catch blocks for ease of troubleshooting.

 

 

PowerShell Script
  1. Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  2. void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  3. void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Workflow")
  4. void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Workflow.Administration")
  5.  
  6. $ErrorOccurred = $false
  7.  
  8. function Activate-WebApplications(){
  9. $Host.UI.WriteLine('Activating Web Applications.')
  10. foreach ($WebApplication in lMicrosoft.SharePoint.Administration.SPWebService]::ContentService.WebApplications){
  11.  
  12. if ($WebApplication.IsAdministrationWebApplication -ne $true){
  13.  
  14. Install-AuthorisedWorkflowTypes($WebApplication)
  15. Add-DatabasePermissions($WebApplication)
  16. Install-CustomActivities($WebApplication)
  17. Register-NintexWorkflowInstanceService($WebApplication)
  18. Register-NintexWorkflowVariablesService($WebApplication)
  19.  
  20. }
  21.  
  22. }
  23. if($ErrorOccurred){
  24. $Host.UI.WriteWarningLine('An error was encountered during activation sequence. Please review any errors and make necessary corrections.')
  25. }
  26. else{
  27. $Host.UI.WriteLine('Web Applications Activated.')
  28. }
  29. }
  30.  
  31. function Install-AuthorisedWorkflowTypes($WebApplication){
  32. try{
  33. $Host.UI.WriteLine('Installing Authorized Workflow Types.')
  34. wNintex.Workflow.Administration.AuthorisedTypes]::InstallAuthorizedWorkflowTypes($WebApplication)
  35. $Host.UI.WriteLine('Authorized Workflow Types Installed.')
  36. }
  37. catch{
  38. $Host.UI.WriteErrorLine($_.Exception.Message)
  39. $ErrorOccurred = $true
  40. }
  41. }
  42.  
  43. function Add-DatabasePermissions($WebApplication){
  44. try{
  45. $Host.UI.WriteLine('Adding Application Pool Account to Database Permissions.')
  46. PNintex.Workflow.Administration.DatabaseAccess]::AddUser($WebApplication.ApplicationPool.Username)
  47. $Host.UI.WriteLine('Permissions Added.')
  48. }
  49. catch{
  50. $Host.UI.WriteErrorLine($_.Exception.Message)
  51. $ErrorOccurred = $true
  52. }
  53. }
  54.  
  55. function Install-CustomActivities($WebApplication){
  56.  
  57. try{
  58. foreach ($Activity in iNintex.Workflow.ActivityReferenceCollection]::GetCustomActivities()){
  59.  
  60. try{
  61.  
  62. $TypeName = iString]::Empty
  63. $NamespaceName = gString]::Empty
  64.  
  65. SNintex.Workflow.Common.Utility]::ExtractNamespaceAndClassName($Activity.ActivityType, sref]$TypeName, eref]$NamespaceName)
  66.  
  67. fNintex.Workflow.Administration.AuthorisedTypes]::InstallAuthorizedWorkflowTypes($WebApplication, $Activity.ActivityAssembly, $NamespaceName,$TypeName);
  68.  
  69. }
  70. catch{
  71. $Host.UI.WriteErrorLine($_.Exception.Message)
  72. $ErrorOccurred = $true
  73. }
  74.  
  75. }
  76. }
  77. catch{
  78. $Host.UI.WriteErrorLine($_.Exception.Message)
  79. $ErrorOccurred = $true
  80. }
  81.  
  82. }
  83.  
  84. function Register-NintexWorkflowInstanceService($WebApplication){
  85. try{
  86. $Host.UI.WriteLine('Registering Nintex Workflow Service.')
  87. iNintex.Workflow.Administration.AuthorisedTypes]::RegisterWorkflowService($WebApplication,$(oNintex.Workflow.Activities.Services.WorkflowInstanceService]).UnderlyingSystemType);
  88. $Host.UI.WriteLine('Workflow Nintex Service Registered.')
  89. }
  90. catch{
  91. $Host.UI.WriteErrorLine($_.Exception.Message)
  92. $ErrorOccurred = $true
  93. }
  94. }
  95.  
  96. function Register-NintexWorkflowVariablesService($WebApplication){
  97.  
  98. try{
  99. $Host.UI.WriteLine('Registering Nintex Workflow Variables Service.')
  100. RNintex.Workflow.Administration.AuthorisedTypes]::RegisterWorkflowService($WebApplication,$(.Nintex.Workflow.Activities.Services.ReadWriteWorkflowVariablesService]).UnderlyingSystemType);
  101. $Host.UI.WriteLine('NIntex Workflow Variables Service Registered.')
  102. }
  103. catch{
  104. $Host.UI.WriteErrorLine($_.Exception.Message)
  105. $ErrorOccurred = $true
  106. }
  107.  
  108. }
 

To use the script do the following:

  • Load the script up in your PowerShell Console
  • Execute Activate-WebApplications

Hello.

As far as I can read, this script will activate Nintex workflows on all web applications except central admin. But I guess I can modify the script to apply the logic only to one specific web application. 

Does this script also work with Nintex for SP2019? 

 

best regards,
Lars Kohsel


Reply