Vadim Tabakman

This is Part 3 from the previous post on PowerShell Find All Workflows and Export.

We now have the ability to find all our workflows, parse the information and export the workflows to file.  Next, what I would like to do, is have the abililty to republish each of these workflows.  This is a request I've seen a few times, although I haven't really found a need for it myself.

Changes to the PowerShell Script

The way to export and publish a workflow is via a web service call to the site where the workflow lives.  The Nintex Workflow web service url looks like this :

http://[siteurl]/_vti_bin/NintexWorkflow/Workflow.asmx

You can find some more information about this web service in the Nintex Workflow 2010 SDK.

Here is what the script looks like now.

[IO.Directory]::SetCurrentDirectory((Convert-Path (Get-Location -PSProvider FileSystem)))

$operation = $args[0]

# build the credential object
$secpasswd = ConvertTo-SecureString $args[2] -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($args[1],$secpasswd);

# check if we are in the same location as the nwadmin.exe
if(Test-Path(".\nwadmin.exe"))
{
  # find all the workflows and store them in a variable
  $foundworkflows = .\nwadmin -o FindWorkflows

  # read the contents of the NWAdmin -o FindWorkflows
  # $foundworkflows = get-content "C:\Program Files\Nintex\Nintex Workflow 2010\workflows.txt"

  foreach($line in $foundworkflows)
  {
    if($line.StartsWith("Active at "))
    {
      # get the site url
      $site = $line.Replace("Active at ","");
    }
    if($line.StartsWith("-- "))
    {
      # get the list name
      $list = $line.Replace("-- ","");
    }
    if($line.StartsWith("---- "))
    {
      # get the workflow name
      $workflowname = $line.Replace("---- ","");

      $webserviceurl = $site + "/_vti_bin/NintexWorkflow/Workflow.asmx"

      # get web service proxy
      $page = New-WebServiceProxy -Uri $webserviceurl -Credential $credential;
      $page.Url = $webserviceurl;

      # ($page | Get-Member -Name ExportWorkflow).definition;

      # export workflow
      try
      {
        if($list -eq "Site Workflow")
        {$exportedworkflow = $page.ExportWorkflow($workflowname,$list,'Site');}
        elseif($list -eq "Reusable workflow template")
        {$exportedworkflow = $page.ExportWorkflow($workflowname,$list,'Reusable');}
        elseif($list -eq "Site collection reusable workflow template")
        {$exportedworkflow = $page.ExportWorkflow($workflowname,$list,'GloballyReusable');}
        else
        {$exportedworkflow = $page.ExportWorkflow($workflowname,$list,'List');}

        switch($operation)
        {
          "RepublishAll"
          {
            # republish this workflow
            try
            {
              $publishresult = $page.PublishFromNWFXml($exportedworkflow,$list,$workflowname,$True);
            }
            catch
            {
              echo $error;
            }
            if($publishresult -eq "")
            {
               echo "Publish Result is empty";
            }
          }
          "ExportAll"
          {
            $localfile = "{0}\{1}.nwf" -f [IO.Directory]::GetCurrentDirectory(),$workflowname;
            echo "Exporting workflow to - " $localfile;
            $stream = [System.IO.StreamWriter] $localfile;
            $stream.WriteLine($exportedworkflow);
            $stream.close();
          }
          default
          {
            echo "No operation";
          }
        }

      }
      catch [system.exception]
      {
        # $error[0];
        $_.Exception.Message;
        $exportedworkflow = "";
      }

      # only do this for the first workflow
      # break;
    }
  }
}
else
{
  echo "NWAdmin doesn't exist.  Change directory to where NWAdmin.exe lives.";
}

What this script does, is it finds each workflow from the NWAdmin command, then connects to the web service running on that site and makes a call to the ExportWorkflow web method followed by a PublishFromNWFXml method call. 

How to run this PowerShell Script

Put the script file in to : c:\Program Files\Nintex\Nintex Workflow 2010

To run this script, open the SharePoint 2010 Management Shell. 

Change directories to c:\Program Files\Nintex\Nintex Workflow 2010

Run the script to Export:

   .\AllWorkflowsV3.ps1 ExportAll domain\username password

Run the script to Republish:

   .\AllWorkflowsV3.ps1 RepublishAll domain\username password

Conclusion

You should now be able to run this and export all your workflows to NWF files for backup or republish all your workflows.

Don't be afraid to tweak this to add more features that you may need.

Update

Script now supports List workflows, Site workflows, Reusable Workflow Templates and Site Collection Resuable Workflow Templates.

Downloads

Posted by Vadim Tabakman Wednesday, August 15, 2012 2:01:00 PM Categories: Nintex Nintex Workflow PowerShell
Copyright Vadim Tabakman
Rate this Content 3 Votes

Comments

Thursday, August 16, 2012 2:53:04 PM
Kevin

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

Wow Vadim, this is awesome. Thanks so much for posting this up, it is a huge timesaver for me and some of the guys I work with. Seriously amazing....

I'm getting an error and have output the error text. I'll send you an email with the errors, easier than posting it up here.

Thanks again.

Thursday, August 16, 2012 3:07:13 PM

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

Thanks Kevin,

It looks like even though there's an error, the workflow still gets exported.

Here is the error and I'll be looking into it when I can:

Exception calling "ExportWorkflow" with "3" argument(s): "Server was unable to process request. ---> Workflow not found.
"
At C:\Program Files\Nintex\Nintex Workflow 2010\FindAllWorkflows.ps1:44 char:49
+         $exportedworkflow = $page.ExportWorkflow <<<< ($workflowname,$list,'List');
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

 

Thursday, August 16, 2012 4:00:56 PM

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

Ok.  Script updated, so that should fix the export errors :)

Thursday, March 7, 2013 3:54:03 AM
Dan

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

can this export and import into a different farm ?

Thursday, March 7, 2013 7:04:17 AM

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

Hi Dan,

not with this script, since it only takes one set of site url/credentials.  You'd need to tweak it to export from one site and import into another farm.

cheers,

Vadim

Tuesday, March 12, 2013 8:44:11 PM
Kevin

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

Have just used this once again after some modifications to it so it can be used for MOSS 2007! Again, it has saved me so much time.

A couple of changes....

Add the following two lines to the top of the script

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")

As there is only one type of workflow (list) the Site and Reusable export lines can be removed, so now the try block looks like

try
{
$exportedworkflow = $page.ExportWorkflow($workflowname,$list);
switch($operation) etc etc...

Thats about it.

Thanks Vadim!

Tuesday, March 12, 2013 8:45:46 PM
Kevin

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

Just one more note on the change to the ExportWorkflow line I pasted in my previous comment. The ExportWorkflow method in 2007 only takes in two parameters, WorkflowName and ListName so the WorkflowType must be removed from the method call.

Kev

Friday, August 23, 2013 12:36:41 PM

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

Hi!  I've tweaked this quite a bit to my own purposes, but one issue I'm running into is with lists that are using special characters.  I can't figure out how do deal with those...here's my error below.  Any suggestions?  Thanks so much!

Exception calling "ExportWorkflow" with "3" argument(s): "Server was unable to process
request. ---> Cannot find list.
Parameter name: listName
Actual value was Dave&#39;s list."
At C:\Program Files\Nintex\Nintex Workflow 2010\AllWorkflowsV2.ps1:125 char:50
+ {$exportedworkflow = $page.ExportWorkflow <<<< ($workflowname,$list,'List');
}
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

 

Wednesday, March 9, 2016 8:37:48 AM
Jamie Van Dusen
Gravatar

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

Hello there,

 

I had no issues running the export script, but seem to get many of the following while Republishing. ANy thoughts?

At C:\Program Files\Nintex\Nintex Workflow 2010\AllWorkflowsV3.ps1:53 char:50
+         {$exportedworkflow = $page.ExportWorkflow <<<< ($workflowname,$list,'
List');}
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Wednesday, March 9, 2016 10:10:57 AM

re: Nintex Workflow - PowerShell Find All Workflows and Export or Republish Part 3

Hi Jamie,

I'm not sure what that is.  It could be that some information is not being passed to the script.  Or maybe the web service has changed but I haven't heard anything about that happening.

I don't have access to an environment to test this out.

Can you share what your command line looked like when you ran the script?

Vadim

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register





 

Statistics

  • Entries (249)
  • Comments (1729)

Categories