Friday, 30 October 2015

Migrate Nintex Workflow from one Sharepoint List to another.

# Keep new/updated .nwf Files in a Physical Drive.
# Below code import .nwf file from a physical location and publish to a destination List by invoking “/_vti_bin/nintexworkflow/workflow.asmx” service


Add-PSSnapin Microsoft.Sharepoint.Powershell
############ Clear the contents of the Text File to maintain Logs #############

Write-Output "" > D:\NintexWFAutodeployment.txt

##################################################################
$SPDestSites = @("<Destination Site URL 1>","<Destination Site URL 2>","<Destination Site URL N>")
$Count = 0
foreach($SPDestSite in $SPDestSites)
{
$Count++
Write-Output "######## $($Count)) SiteURL: $($SPDestSite) #########"  >>  D:\AutoDeployment_Status\NintexWFAutodeployment.txt
     $DestSite = $SPDestSite
     $SPWeb = Get-SPWeb -Identity $DestSite
     $SPList = $SPWeb.Lists["Source List Name"]
     #Nintex Web Service URL
     $WebSrvUrl=$SPWeb.Url+"/_vti_bin/nintexworkflow/workflow.asmx"
     try{
         $proxy=New-WebServiceProxy -Uri $WebSrvUrl -UseDefaultCredential
     }
    catch{
    write-Output "Exception: $($_.Exception.Message)" >> D:\NintexWFDeployment.txt
     }
     $proxy.URL=$WebSrvUrl

############## Location of Workflow files #################

     $NWFcontent = Get-Content "D:\NintexWorkflowDeploy\MigrateNintexWF.nwf"

     #Location of  CreateTask_WF.nwf file

     $WorkflowName = "MigrateNintex_WF" #Workflow Name   
                                                           
       #####################################################

     $proxy.PublishFromNWFXml($NWFcontent, $SPList ,$WorkflowName, $true)

     Write-Output "Workflow Published to: "$SPList.Title >> D:\NintexWFDeployment.txt
    
}

No comments:

Post a Comment