Deploy Nintex Workflow to Multiple Lists with PowerShell and Nintex Web Service

Requirement: We have three Nintex workflows. These three workflows to be deployed to all document libraries of a sub-site.

Nintex workflows provides web services to deploy Nintex workflow to multiple lists and libraries, which is explained in one of the Nintex whitepapers: How to create a workflow that automatically deploys other workflows?, which calls the web service to publish provided workflow to multiple site’s lists.

Instead of creating another workflow to deploy a workflow, I decided to use PowerShell and Nintex Web Service to deploy workflows on multiple lists.

You can use the same method, if you want to update your existing workflow with new workflow content!

Here goes my PowerShell script:

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Region MOSS2007-CmdLets

Function global:Get-SPSite()
{
  Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )
 
   if($SiteCollURL -ne '')
    {
    return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
   }
}

Function global:Get-SPWeb()
{
 Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
  $site = Get-SPSite($SiteURL)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();
            }
    return $web
}
#EndRegion

#Target SharePoint site URL
$WebURL="https://sharepoint.crescent.com/finance/CustomerApproval/"
#Get the Target Site
$Web=Get-SPWeb $WebURL
#Get the Target Lists 

#Nintex Web Service URL
$WebSrvUrl=$WebURL+"_vti_bin/nintexworkflow/workflow.asmx"

$proxy=New-WebServiceProxy -Uri $WebSrvUrl -UseDefaultCredential
$proxy.URL=$WebSrvUrl
#Path of the NWF Workflow File
$WorkflowFile= "C:\Documents and Settings\Salaudeen\Desktop\CustApproval.nwf"

#Get the Workflow from file
$NWFcontent = get-content $WorkflowFile

foreach($List in $web.lists)
 {
   #Get only document libraries. Leave the hidden and "Pending Approval Task" Document Library
   if ( ($List.BaseType -eq "DocumentLibrary") -and ($List.Hidden -eq $false) -and ($List.Title -ne "Pending Approval Tasks") )
   {
     write-host "Workflow is being Published to: "$List
     $proxy.PublishFromNWFXml($NWFcontent, $List.Title ,$List.Title+" Approval", $true)
     write-host "Done!"
   }
 }
If your workflow fails for some reason (e.g. column not found in the target list), workflow will be placed under “Unpublished workflows” category

In another situation, When I had to Deploy Nintex workflow to specific lists I used this method:

#Array to hold list names
$lists= @("Finance", "Human Resources", "Information Technology", "Management System", "Safety" , "Sales and Marketing" , "Security Services", "Supply Chain Ops")

#loop through each list and deploy the workflow
foreach($List in $lists)
 {
     $proxy.PublishFromNWFXml($NWFcontent, $List ,$List+" Approval", $true)
     write-host "Workflow Published to: "$List
 }

In some cases, This script errored on the following line:
$proxy.PublishFromNWFXml($NWFcontent, $List ,”IM” +$List+” Approval”, $true)
with Error message:
Exception calling “PublishFromNWFXml” with “4” argument(s): “Server was unable to process request. —> An error has occurred.”

Made a change by breaking the line into two as below and solved the issue:
$WorkflowName = “Terminate “+$ListName+” Approval”
$proxy.PublishFromNWFXml($NWFcontent, $ListName ,$WorkflowName, $true)

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

3 thoughts on “Deploy Nintex Workflow to Multiple Lists with PowerShell and Nintex Web Service

  • Don’t forget to enter -encoding UTF8 as parameter after get-content-cmdlet or you will get problems with for e.g. german umlauts if you are using them in your workflows.

    Reply
  • Hi,
    I am getting below error even running with service account

     Exception calling “PublishFromNWFXml” with “4” argument(s): “Server was unable to process request. —> Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))” 
    At D:Nintext.ps1:51 char:6 
    +      $proxy.PublishFromNWFXml($NWFcontent, $List.Title ,$List.Title, $true) 
    +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException 
        + FullyQualifiedErrorId : SoapException 

    Reply
    • Any solution about how you fixed that issue? I have mixed method for sign in to the target web application. (FBA and Windows Authentication).

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *