Vadim Tabakman

Jump to bottom

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? Click the appropriate image below

|

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 $_;
}

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

Posted by Vadim Tabakman Wednesday, March 13, 2013 10:50:00 PM Categories: Nintex Nintex Workflow PowerShell SharePoint
Copyright Vadim Tabakman
Rate this Content 0 Votes

Comments

Thursday, March 14, 2013 3:54:46 PM
Dan

re: Nintex Workflow - Start Workflow with PowerShell

What if the workflow had start variables .. Could you pass these tot he workflow ?

Thursday, March 14, 2013 11:38:03 PM

re: Nintex Workflow - Start Workflow with PowerShell

Hi Dan,

no, passing variables is completely impossible..... with this script in the current state :)

When I have time, I'll tweak it to handle the association data, which is some xml that wraps the start variables.

cheers,

Vadim

Monday, July 15, 2013 10:48:02 AM
Larry Tenison

re: Nintex Workflow - Start Workflow with PowerShell

Vadim, if I want to start a SITE workflow, how does the script need to change?

Thanks,

LT

Monday, July 15, 2013 11:00:29 AM

re: Nintex Workflow - Start Workflow with PowerShell

Hi Larry,

for the Nintex Workflow script, instead of the "StartWorkflowOnListItem" method call, you'd be looking at calling the "StartSiteWorkflow" web method.

Let me know if you have any issues and I can look further into it.

cheers,

Vadim

Monday, September 2, 2013 10:23:50 PM
Matthew

re: Nintex Workflow - Start Workflow with PowerShell

Hi Vadim,

I'm fairly new to Nintex and not sure what variables I need to change in the script to fit my needs? What details do I put into nwlogin and itemid for instance?

Thank you!

Tuesday, September 3, 2013 12:00:25 PM

re: Nintex Workflow - Start Workflow with PowerShell

Hi Matthew,

the nwlogin is the credentials you need to access your SharePoint site.

the itemId is the ID of the item you want to start a workflow on.  List workflow instances are linked to a specific item in the list, so you need to tell it which Item you want to start the workflow on.

cheers,

Vadim

Tuesday, September 3, 2013 4:46:45 PM
Matthew

re: Nintex Workflow - Start Workflow with PowerShell

Thanks Vadim, much appreciated! What if I wanted to run a Nintex workflow on all the items in a list/library?

Cheers!

Friday, September 27, 2013 10:25:22 AM
Eric

re: Nintex Workflow - Start Workflow with PowerShell

Hi Vadim;

I am new to Nintex. Can I use it to resolve my following problem?

I have about 170 sites and want to allow users to build their own libraries, as they need. I decided to create a WF to do that.

The best option, from a maintenance point of view, is to create a reusable WF in Site Collection and to start it using Powershell. Is it possible? How should I deal with variables such as "Library Name" and other library options?

If that is not the way to resolve this issue, how do you suggest to do it?

 

Thanks a lot

 

Have a nice day

Eric

Sunday, October 20, 2013 1:30:52 AM
Akhoy

re: Nintex Workflow - Start Workflow with PowerShell

Hi Vadim,

 

How do we find out if the workflow is a site or a list workflow? Is there an IF condition that can be written for that?

Tuesday, March 18, 2014 9:07:03 PM
Deepesh

re: Nintex Workflow - Start Workflow with PowerShell

HI, 

i have to stop all the workflow in the list item.

Tuesday, March 18, 2014 11:08:59 PM

re: Nintex Workflow - Start Workflow with PowerShell

Hi Akhoy,

I haven't figure out how to find out if it's a Site or List Workflow.  But since you're probably updating the script or running the script, you should know what kind of workflow you're trying to run.

Hi Deepesh,

I don't know if you're asking something or just making a statement :).  This post has nothing to do with stopping workflows.  It's about using PowerShell to start a workflow instance.

cheers,

Vadim

Friday, May 30, 2014 1:00:42 AM
Bennie Rothmann
Gravatar

re: Nintex Workflow - Start Workflow with PowerShell

Hi Vadim,

When I run the script to start the Nintex workflow I get the following error:

Error on itemID 109328 Exception calling "StartWorkflowOnListItem" with "4" argument(s): "Server was unable to process request. ---> Cannot find list.
Parameter name: listName
Actual value was e-Leave."

I can verify that the list "e-Leave" does exist. May it be the hyphen?

Thanks,
Bennie

 

Friday, May 30, 2014 3:01:28 AM
Bennie Rothmann
Gravatar

re: Nintex Workflow - Start Workflow with PowerShell

Sorry, got it figured out. I was looping through a couple of items and had to modify the $page.url prior the loop:

$page.Url = $webserviceurl;

Bennie

Friday, May 30, 2014 7:51:02 AM

re: Nintex Workflow - Start Workflow with PowerShell

Glad you figured it out Bennie.

cheers,

Vadim

Thursday, July 9, 2015 3:50:35 AM
Lukas
Gravatar

re: Nintex Workflow - Start Workflow with PowerShell

Hi,

I neded to send from powershell to workflow some association data (in my case it was XML and in my workflow used  action "Query XML").
If you need send asocitaion data from PowerShell to Nintex Workflow (StartWorkflowOnListItem method), you need to add fourth parameter - Associtaion Data in correct format.

1) Sending text as string:
<Data><inputXML>Text of input workflow variable</inputXML></Data>

2) Sending text as xml:
<Data><inputXML>XML Encoded text of input workflow variable</inputXML></Data>

 

For example there is my script with sending text as string:

# Loads SharePoint PowerShell SnapIn
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy  unrestricted -Force # answer Y
$spCmdlets = Get-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction silentlycontinue
if ($spCmdlets -eq $Null) { Add-PSSnapin Microsoft.SharePoint.PowerShell }
[void][System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

# Obtains Web application informations
$siteCollectionURL = "https://portal.company.com"
$spSite = Get-SPSite $siteCollectionURL
$spWeb = Get-SPWeb $siteCollectionURL
$spWebURL = $spWeb.Url
$spListURL = $($spWeb.Url + "/Lists/ListName")
$spList = $spWeb.GetList($spListURL)
$listItemId = "49"

# Nintex Workflow Web Service
$workflowName = "NotifyMe"
### body of data to transfer must be XML Encoded ####
$transferData = "&lt;inputData&gt;&lt;xmlNode1&gt;data in XML node 1&lt;/xmlNode1&gt;&lt;xmlNode2&gt;data in XML node 2&lt;/xmlNode2&gt;&lt;xmlNode3&gt;data in XML node 3&lt;/xmlNode3&gt;&lt;/inputData&gt;"
[String]$associationData = "<Data><inputXML>" + $transferData + "</inputXML></Data>"
$username = "MIBACZ\svc_sp_farm"
$password = "stUx4thUx"
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username,$secpasswd);
$proxyWSUrl = $spWebURL + "/_vti_bin/NintexWorkflow/workflow.asmx"
$proxyWSUrl = $proxyWSUrl
$proxy = New-WebServiceProxy -Uri $proxyWSUrl -Credential $credential
$proxy.Url = $proxyWSUrl
$workflow = $proxy.StartWorkflowOnListItem($listItemId,$spList,$workflowName,$associationData)

Thursday, July 9, 2015 9:55:39 AM

re: Nintex Workflow - Start Workflow with PowerShell

Thanks for sharing that Lukas.  That's awesome.

Monday, August 24, 2015 7:25:50 PM
Kyle
Gravatar

re: Nintex Workflow - Start Workflow with PowerShell

Hi Vadim,

I manage to run the power shell script by trigger the SiteWorkflow at SharePoint Windows Authentication.

But if the Web Application is Forms Based Authentication, the script cannot work.

I mange to find some information that at FBA, we needs to use Authentication.asmx to get the cookies first before we can trigger the workflow. Do you have any idea on doing this?

Thank You

Thursday, August 27, 2015 8:58:41 AM

re: Nintex Workflow - Start Workflow with PowerShell

Hi Kyle,

No I don't.  I know you need to call that web service to generate a token that you use in other web service calls. But I don't have an FBA environment to mess around with this and I'm pretty slammed at the moment with work.

If you do figure it out, please share your findings somewhere.

cheers,

vadim

Monday, October 12, 2015 1:13:58 PM
Esteban Culiat
Gravatar

re: Nintex Workflow - Start Workflow with PowerShell

I've copied the function and place it as an "in-line" function to my powershell script.  Somehow, I'm getting an error that says

New-WebServiceProxy: Could not file file 'c:\Users\*****\AppData\Local\Temp\2\9jce0rrn.dll'

Please help.

 

Monday, October 12, 2015 1:35:56 PM

re: Nintex Workflow - Start Workflow with PowerShell

Hi Esteban,

I have no idea what that is.  Maybe some temp file.

Are you trying to deploy a debug assembly?

vadim

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





 

Statistics

  • Entries (235)
  • Comments (1721)

Categories