Solved

Start PowerShell Script remotely with Nintex Workflow

  • 12 September 2023
  • 4 replies
  • 300 views

Badge +1

Hi there

I have a PowerShell Script stored on our AD Server, which creates a new AD User. I'd like to execute that PS-Script with my Nintex Workflow with some Variables such as first name. But I have not been able to find a way to do this except for Programming my own API with C# or Python which would be running on our AD-Server and then send my API-request to that API using the "Web-request" or "Web-Call" Workflow Action.

I have seen this Nintex RPA Action for executing a PowerShell Script: https://help.nintex.com/archives/en-US/rpa/v1/Actions/PowerShell.htm

Does something similar to this exist for Nintex for Sharepoint 2019? Or can I somehow add this feature to Nintex for SharePoint 2019?

Or do you know another way to execute PowerShell Scripts remotely or create AD Users remotely from a Nintex for SharePoint 2019 Workflow?

Thanks for any replies. :)

icon

Best answer by Jake 15 September 2023, 10:47

View original

4 replies

Userlevel 3
Badge +12

Check out the workflow action, Create AD user and see if it could work for your use case. It may do the same thing your powershell script is trying to do.

 

Jason

 

Badge +1

Thank you for your reply. It’s an interesting module. But it does not really offer all the functionality I am looking for. 

Such as adding information to custom AD-User Attributes. Do you know a way how I can execute PowerShell Code from within my workflow like the Nintex RPA PowerShell module.

Userlevel 3
Badge +12

I don’t know of a Nintex supported way to call an external PowerShell script like that in Nintex for SP off the top of my head. I’ll ask around to see if anyone has implemented something in the past.

Userlevel 5
Badge +13

Hi @Nintex_Admin_xyz 

there is an extension here but it is a couple years out of date and I cannot guarantee it will work: 

 

Alternatively I would recommend looking into building an event receiver that looks at a given Sharepoint list, when an item is created in the list it can execute a Powershell script, that way Nintex would only need to populate the list with the users you want to create and the Powershell script will react to it, I would recommend having the Powershell script remove the records from the list on completion to ensure no unwanted build-up. 

this is the article for visual studio:
https://learn.microsoft.com/en-us/visualstudio/sharepoint/how-to-create-an-event-receiver?view=vs-2022&tabs=csharp

TL:DR-

  1. Open Visual Studio.
  2. Create a new SharePoint 2019 - Empty Project.
  3. Right-click on the project in Solution Explorer > Add > New Item.
  4. Choose "Event Receiver" and name it.
  5. Choose the type of event you want (in your case, an item added event for a list).

It should generate an ItemAdded method in the receiver and you can add logic like this to execute a script:

System.Diagnostics.Process.Start("powershell.exe", @"& 'C:\path\to\your\script.ps1'");

Then to attach your event receiver to a specific list you need to edit the Elements.xml like below, the list ID template of 100 will be attached.:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="100">
<Receiver>
<Name>MyEventReceiverItemAdded</Name>
<Type>ItemAdded</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>YourNamespace.YourEventReceiverClassName</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>

Another way which I prefer would be to use Powershell to attach it which can happen after you deploy it by right clicking on the project in VS and deploying.

Add-PSSnapin Microsoft.SharePoint.PowerShell

$web = Get-SPWeb "http://your_sharepoint_site_url"
$list = $web.Lists["Your List Name"]

$eventReceiver = $list.EventReceivers.Add()
$eventReceiver.Assembly = "YourAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=your_public_key_token"
$eventReceiver.Class = "YourNamespace.YourEventReceiverClassName"
$eventReceiver.Type = [Microsoft.SharePoint.SPEventReceiverType]::ItemAdded
$eventReceiver.SequenceNumber = 1000
$eventReceiver.Update()

$web.Dispose()

If you don’t have VS then I think you can do this in VS code but I have never done it, most of what I am writing here is from memory/articles such as this which covers event receivers in more detail:

https://www.c-sharpcorner.com/article/introduction-of-sharepoint-event-receivers/

Jake

Reply