aaron.labiosa@nintex.com

How to Activate Web Applications via PowerShell

Blog Post created by aaron.labiosa@nintex.com Champion on May 21, 2015

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. $ErrorOccurred = $false
  6. function Activate-WebApplications(){
  7. $Host.UI.WriteLine('Activating Web Applications.')
  8. foreach ($WebApplication in [Microsoft.SharePoint.Administration.SPWebService]::ContentService.WebApplications){
  9. if ($WebApplication.IsAdministrationWebApplication -ne $true){
  10. Install-AuthorisedWorkflowTypes($WebApplication)
  11. Add-DatabasePermissions($WebApplication)
  12. Install-CustomActivities($WebApplication)
  13. Register-NintexWorkflowInstanceService($WebApplication)
  14. Register-NintexWorkflowVariablesService($WebApplication)
  15. }
  16. }
  17. if($ErrorOccurred){
  18. $Host.UI.WriteWarningLine('An error was encountered during activation sequence. Please review any errors and make necessary corrections.')
  19. }
  20. else{
  21. $Host.UI.WriteLine('Web Applications Activated.')
  22. }
  23. }
  24. function Install-AuthorisedWorkflowTypes($WebApplication){
  25. try{
  26. $Host.UI.WriteLine('Installing Authorized Workflow Types.')
  27. [Nintex.Workflow.Administration.AuthorisedTypes]::InstallAuthorizedWorkflowTypes($WebApplication)
  28. $Host.UI.WriteLine('Authorized Workflow Types Installed.')
  29. }
  30. catch{
  31. $Host.UI.WriteErrorLine($_.Exception.Message)
  32. $ErrorOccurred = $true
  33. }
  34. }
  35. function Add-DatabasePermissions($WebApplication){
  36. try{
  37. $Host.UI.WriteLine('Adding Application Pool Account to Database Permissions.')
  38. [Nintex.Workflow.Administration.DatabaseAccess]::AddUser($WebApplication.ApplicationPool.Username)
  39. $Host.UI.WriteLine('Permissions Added.')
  40. }
  41. catch{
  42. $Host.UI.WriteErrorLine($_.Exception.Message)
  43. $ErrorOccurred = $true
  44. }
  45. }
  46. function Install-CustomActivities($WebApplication){
  47. try{
  48. foreach ($Activity in [Nintex.Workflow.ActivityReferenceCollection]::GetCustomActivities()){
  49. try{
  50. $TypeName = [String]::Empty
  51. $NamespaceName = [String]::Empty
  52. [Nintex.Workflow.Common.Utility]::ExtractNamespaceAndClassName($Activity.ActivityType, [ref]$TypeName, [ref]$NamespaceName)
  53. [Nintex.Workflow.Administration.AuthorisedTypes]::InstallAuthorizedWorkflowTypes($WebApplication, $Activity.ActivityAssembly, $NamespaceName,$TypeName);
  54. }
  55. catch{
  56. $Host.UI.WriteErrorLine($_.Exception.Message)
  57. $ErrorOccurred = $true
  58. }
  59. }
  60. }
  61. catch{
  62. $Host.UI.WriteErrorLine($_.Exception.Message)
  63. $ErrorOccurred = $true
  64. }
  65. }
  66. function Register-NintexWorkflowInstanceService($WebApplication){
  67. try{
  68. $Host.UI.WriteLine('Registering Nintex Workflow Service.')
  69. [Nintex.Workflow.Administration.AuthorisedTypes]::RegisterWorkflowService($WebApplication,$([Nintex.Workflow.Activities.Services.WorkflowInstanceService]).UnderlyingSystemType);
  70. $Host.UI.WriteLine('Workflow Nintex Service Registered.')
  71. }
  72. catch{
  73. $Host.UI.WriteErrorLine($_.Exception.Message)
  74. $ErrorOccurred = $true
  75. }
  76. }
  77. function Register-NintexWorkflowVariablesService($WebApplication){
  78. try{
  79. $Host.UI.WriteLine('Registering Nintex Workflow Variables Service.')
  80. [Nintex.Workflow.Administration.AuthorisedTypes]::RegisterWorkflowService($WebApplication,$([Nintex.Workflow.Activities.Services.ReadWriteWorkflowVariablesService]).UnderlyingSystemType);
  81. $Host.UI.WriteLine('NIntex Workflow Variables Service Registered.')
  82. }
  83. catch{
  84. $Host.UI.WriteErrorLine($_.Exception.Message)
  85. $ErrorOccurred = $true
  86. }
  87. }

To use the script do the following:

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

Outcomes