Monday, February 4, 2013

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 whitepaper: 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:


#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)
    return $web

#Target SharePoint site URL
#Get the Target Site
$Web=Get-SPWeb $WebURL
#Get the Target Lists 

#Nintex Web Service URL

$proxy=New-WebServiceProxy -Uri $WebSrvUrl -UseDefaultCredential
#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 an 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)

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:


  1. 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 

  2. 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.


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...