Nintex Workflow PowerShell

Nintex Workflow – Start Workflow with PowerShell

Starting a workflow via PowerShell can be a useful function and can speed up a lot of work.  I’ve created a couple of scripts to help out.

The first one is a script to start a SharePoint workflow, using the SharePoint object model.

The second one is a script to start a Nintex Workflow, using a call to the Nintex Workflow web service.

Let’s start with whether you want a SharePoint Workflow or a Nintex Workflow?

SharePoint Workflow

# .\SPStartWorkflow.ps1 -siteurl url -nwlogin domain\username -nwpassword password -nwworkflow "workflowname" -list "listname" -itemid id

Param(
    [parameter(Mandatory=$true)]
    [alias("siteurl")]
    $url,
    [parameter(Mandatory=$true)]
    [alias("nwlogin")]
    $login,
    [alias("nwpassword")]
    $password,
    [alias("nwworkflow")]
    $workflowname,
    [alias("list")]
    $listname,
    [alias("itemid")]
    $listitemid)

try
{
  Start-SPAssignment -global;

  $web = Get-SPWeb $url;
  $site = $web.Site;
  $workflowManager = $site.WorkFlowManager;
  $list = $web.Lists[$listname];
  $item = $list.GetItemById($listitemid);

  $association=$list.WorkFlowAssociations | where {$_.Name -eq $workflowname};
  $data=$association.AssociationData;
 
  echo 'Starting workflow...';

  $wf=$workflowManager.StartWorkFlow($item,$association,$data);

  echo 'Workflow started...';

  Stop-SPAssignment -global;
            
}
catch
{
  echo $_;
}

Nintex Workflow

# .\NWStartWorkflow.ps1 -siteurl url -nwlogin domain\username -nwpassword password -nwworkflow "workflowname" -list "listname" -itemid id

            Param(
                [parameter(Mandatory=$true)]
                [alias("siteurl")]
                $url,
                [parameter(Mandatory=$true)]
                [alias("nwlogin")]
                $login,
                [alias("nwpassword")]
                $password,
                [alias("nwworkflow")]
                $workflowname,
                [alias("list")]
                $listname,
                [alias("itemid")]
                $listitemid)

            try
            {
              [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

              $webserviceurl = $url + '/_vti_bin/NintexWorkflow/Workflow.asmx';

              $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
              $credential = New-Object System.Management.Automation.PSCredential($login,$secpasswd);
              $webserviceurl = $webserviceurl
              $page = New-WebServiceProxy -Uri $webserviceurl -Credential $credential;
              $exportedworkflow = $page.StartWorkflowOnListItem($listitemid,$listname,$workflowname,'');
            }
            catch
            {
              echo $_;
            }
$page.Url = $webserviceurl;

Conclusion

Let me know if there are any additions that you feel would make these scripts better.

Downloads

 PowerShell Start SharePoint Designer Workflow: Download PowerShell Script 

 PowerShell Start Nintex Workflow: Download PowerShell Script

Leave a Reply