In this article, let us see how to Import Nintex Workflows in SharePoint using CSOM PowerShell Script.
The code is self-explanatory.
01.ImprotNintexForms
function Import-NintexWorkflow { <# .SYNOPSIS Imports a Nintex workflow .nwf file to a list. .DESCRIPTION Imports a Nintex workflow .nwf file to a list. #> [CmdletBinding()] param( [string]$WebUrl = $(throw "Required parameter -WebUrl missing"), [string]$listName = $(throw "Required parameter -ListName missing"), [string[]]$workflowNames = $(throw "Required parameter -workflowNames missing"), [string]$WorkflowFolderPath = $(throw "Required parameter -WorkflowFolderPath missing"), [bool]$OverwriteExistingVersion = $false ) begin { if(!(Get-PnPConnection)) { throw "There is no PnPConnection" } Write-Host "---- Importing Nintex workflow to '$($listName)' ----" -ForegroundColor Yellow } process { $List = Get-PnPList -Identity $listName $ListID = $List.Id.ToString() $ListName = $List.Title $webServiceUrl = "$WebUrl/_vti_bin/NintexWorkflow/Workflow.asmx" $webServiceProxy = New-WebServiceProxy -Uri $webServiceUrl -UseDefaultCredential $webServiceProxy.URL = $webServiceUrl for ($i=0;$i -lt $workflowNames.Length; $i++) { $WorkflowName = $workflowNames[$i] + "_6" $WorkflowFilePath = $WorkflowFolderPath + "" + $workflowNames[$i] + ".nwf" $nwfContent = Get-Content "$WorkflowFilePath" $utf8 = New-Object System.Text.UTF8Encoding [byte[]] $byteData = $utf8.GetBytes($nwfContent.ToString()) $hasWorkflowPublished = $webServiceProxy.WorkflowExists($WorkflowName,$ListID,"List") Write-Host "Workflow exists status: '$hasWorkflowPublished'" -ForegroundColor Cyan if($hasWorkflowPublished -eq "NameUsedInOtherList" -or $hasWorkflowPublished -eq "NameUsedInThisList") { #May be delete it Write-Host "Workflow already exists '$hasWorkflowPublished', if status is 'NameUsedInOtherList' no changes can be made. Please delete it." -ForegroundColor Cyan } if($hasWorkflowPublished -eq "NameNotUsed" -or ($hasWorkflowPublished -eq "NameUsedInThisList" -and $OverwriteExistingVersion -eq $true)){ $IsPublished = $webServiceProxy.PublishFromNWF($byteData, $ListName, $WorkflowName, $true) if($IsPublished) { Write-Host "Nintex Workflow '$WorkflowName' successfully published to list '$ListName'" -ForegroundColor Green } else { Write-Host "Nintex Workflow '$WorkflowName' could not be published to list '$ListName'" -ForegroundColor Yellow } } } } end { } }
Run.ps1
#=========================================== Description Start ========================================= # # Deploy from a List # Author : Sathish Nadarajan # Date : 03-Feb-2021 #=========================================== Description End====================================== # # ============================================ PreRequisites Start ================================= # #Get-Module -Name *pnp* #Pre Req - SharePoint PnP PowerShell Version 2.25.1804.1 #=============================================PreRequisites End =============================== # #============================================= Initial Setup Start =============================== # cls $Host.UI.RawUI.WindowTitle = "-- Deploy Assets --" $StartDate = Get-Date Write-Host -ForegroundColor White "------------------------------------" Write-Host -ForegroundColor White "| Deploy Assets |" Write-Host -ForegroundColor White "| Started on: $StartDate |" Write-Host -ForegroundColor White "------------------------------------" #Add-PSSnapin Microsoft.SharePoint.PowerShell $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm-ss $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent Set-Location $scriptBase # Create Log File Folder3 if(!(TEST-PATH ".Logs-$LogTime")){ NEW-ITEM ".Logs-$LogTime" -type Directory } # Assign the Log and Progress Files $TranscriptFile = ".Logs-$LogTimeDeploy.Transcript.rtf" try{ stop-transcript|out-null } catch [System.InvalidOperationException]{} start-transcript $TranscriptFile #============================================= Initial Setup End =============================== # # ============================================ Setup Input Paths Start ================================= # #connect to the SharePoint list $sourceWebUrl = 'http://andytest-sp:555/sites/newsite/' $sourceListname = "AssetRegisterV2" $outputFolderPath = ".Logs-$LogTime" $targetWebUrl = 'http://andytest-sp:555/sites/newsite/' $targetListname = "AssetRegister_Test" $workflowNames = @('Send Notification When Child is Promoted as Parent','Send Notification When Asset is deleted') # ============================================ Setup Input Paths End ================================= # Import-Module ".4.ImportNintexWorkflows.ps1" Write-Host "Begin to Execute.." -ForeGroundColor Yellow "Begin to Execute..." | Out-File -FilePath $TranscriptFile -Append Connect-PnPOnline -Url $sourceWebUrl -CurrentCredentials -ErrorAction Inquire Import-NintexWorkflow $targetWebUrl $targetListname $workflowNames $outputFolderPath $true Disconnect-PnPOnline Write-Host "Update Completed.. Press Enter to Exit" -ForeGroundColor Green try{ stop-transcript|out-null } catch [System.InvalidOperationException]{}
Happy Coding
Sathish Nadarajan
Leave a comment