cancel
Showing results for 
Search instead for 
Did you mean: 
eric_halsey
Nintex Newbie

PowerShell Script Custom Workflow Action

Hi All,

I put together a custom Nintex Workflow action that executes PowerShell script based on Christian Glessners’ Execute PowerShell Script Action which is part of his Advanced Workflow Actions for SharePoint Designer 2010 which you can find on CodePlex.

The following variables are provided to your script:

  • $site = the current Microft.SharePoint.SPSite
  • $web = the current Microft.SharePoint.SPWeb
  • $list = the current Microft.SharePoint.SPList (null in site workflows)
  • $item= the current Microft.SharePoint.SPListItem (null in site
    workflows)
  • $ctx = the current workflow context
    Microsoft.SharePoint.WorkflowActions.WorkflowContext
  • $sharePointService = the current
    Microsoft.SharePoint.Workflow.ISharePointService service
  • $listItemService = the curent Microsoft.SharePoint.Workflow.IListItemService
    service

There are also 5 user variables that can be used as both input and output to your script.  One of the great things about this action is that you can require that all scripts have to be signed, thus preventing your workflow designers from writing any PowerShell they want. This is a farm level setting which means you can have it turned off in DEV but require it in TEST & PROD.

You can also pass in an encrypted string which will be decrypted at runtime which can be used for passwords.  Lastly, you can pass in a Secure Store AppId which will retrieve the credentials from the Secure Store Service at runtime and pass it in as the variable $credential as a
System.Net.NetworkCredentials object.

Labels: (2)
Reply
43 Replies
Automation Master
Automation Master

Re: PowerShell Script Custom Workflow Action

That's really a great idea !

And security is included !

Reply
Automation Master
Automation Master

Re: PowerShell Script Custom Workflow Action

Great job, can't wait to try it out!

Reply
Not applicable

Re: PowerShell Script Custom Workflow Action

Really POWER!  great to see that someone posted it out.

It seems like we can start post some custom action out to public

I will find time to post out some custom action I wrote before.

Reply
eric_halsey
Nintex Newbie

Re: PowerShell Script Custom Workflow Action

Just a quick word of advice regarding using this action.  Whenever possible use out of the box Nintex Workflow Actions instead of writing your own PowerShell scripts and running them using this component.  I'm confident the great engineers at Nintex work hard to optimize the code behind their components and side by side they'll probably perform better than custom PowerShell script that we write.  Just as an example of this, I ran a test where I used the Query List Nintex action and ran another test where I wrote PowerShell script using the SPQuery object and an optimized query.  You can see that the Nintex component executed in less than half the time, maybe on third the time, than my less than optimized PowerShell script ran in.  Below you will see the perfmon graph showing the execution of the PowerShell script (B) vs. the execution of the Query List Action (A).

1-8-2015 1-45-41 PM.png

I'm not trying to dissuade you from installing and using the component but just like most things in SharePoint, just because you can, doesn't mean you should .  With a little more optimization ViewFieldsOnly = $true and RowLimit=1, I was able to get my script to perform like the Nintex Query List Action. Below you can see they are closer now A=Nintex Query List & B=PowerShell Action

1-8-2015 2-53-39 PM.png

Reply
Automation Master
Automation Master

Re: PowerShell Script Custom Workflow Action

Well said. But just like a Web Service call can give you that extra extension to perform activities outside of the available actions, so will the possibility of a PowerShell script.

Reply
Not applicable

Re: PowerShell Script Custom Workflow Action

Hi

Great idea but I can't get it to work. (Lack of installation instructions doesn't help).

I figured I need to copy the contents of the layouts folder and the features folder but perhaps I need to do something else?

The action appears in NWF but when I drag it to use it, nothing happens.

0 Kudos
Reply
Automation Master
Automation Master

Re: PowerShell Script Custom Workflow Action

eric halsey‌, I didn't check, but does the feature activate automatically deploy the action to the available actions when the solution is deployed? I wanted to double check to help Andy Scott‌ with his question.

Reply
eric_halsey
Nintex Newbie

Re: PowerShell Script Custom Workflow Action

Hi Andy,

You can get the solution file (.wsp) in the downloads section on CodePlex.  You can run the following PowerShell script assuming you change the path to where you saved the wsp (L:\temp) and your web application url (http://intranet).  Also, wait a couple of minutes after you execute the install-solution command and before you run the enable-spfeature command.

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {

    Add-PSSnapin "Microsoft.SharePoint.PowerShell"

}

add-spsolution L:\temp\NintexCustomWFActions.wsp

install-spsolution NintexCustomWFActions.wsp -GACDeployment

enable-spfeature NintexCustomWFActions_NintexCustomWFActions -Url http://intranet

Go to Central Administration -> Nintex Workflow Management -> Managed Allowed Actions and make sure the NintexCustomWFActionsExecutePowerShell item is checked.  You should now be able use the custom action.  Please see the CodePlex page for instructions on how to use it as it does require either signing every script or disabling script signing.

If you need help on adding and installing SharePoint solutions you can read the following Deploy solution packages (SharePoint Server 2010).

If you need additional help on activating web application features you can go to Enable-SPFeature (for 2013 but is basically the same as 2010).

Let us know how it goes.

Reply
eric_halsey
Nintex Newbie

Re: PowerShell Script Custom Workflow Action

Hi Andrew,

I thought so.  However, when I uninstalled it and tested the deployment commands I put together for Andy, it wasn't enabled so I'm not 100% sure.  I put in the steps to check it just in case.

0 Kudos
Reply