0 votes

How can I execute a Business Rule through PowerShell?

I have a Business Rule that fires when a User is created. I have a custom field on the User that can be updated though the Web Interface. I want to be able to fire this Business Rule based on the value in this custom field, when the User is updated. Is it possible?

by (730 points)


As far as we understand, you have a certain PowerShell script that updates a certain property of a user account, and you want a Business Rule to be triggered when the property is updated. Is that correct?

If that's correct, what kind of a script is it? Is it launched from a Business Rule, Custom Command or Scheduled Task or is this a stand-alone script that you launch directly from PowerShell?


The PowerShell script is executed though a Business Rule (1), after a user is updated.

There is another Business Rule (2) that executes after a user is created.

I want the PowerShell script that executes when the User is modified to be able to trigger the Business Rule (2).


After some thought, Is it possible to setup a Business Rule to fire when a User is Created and when a User is Updated? This might also solve my problem.

1 Answer

0 votes
by (215k points)

A Business Rule cannot be launched manually, it can be triggered only by the event before/after which it is configured to be run. Also, a Business Rule cannot be configured to be launched by two different events simultaneously.

However, you can achieve what you want with the help of a Custom Command. You can create a new Custom Command and move all the actions and conditions of Business Rule [2] to the Custom Command.

Then, you can call your Custom Command both from the Business Rule triggered after user creation and from your PowerShell script.

To create a Business Rule that executes a Custom Command after user creation:

  1. Create a new Business Rule.
  2. On the 2nd step of the Create Business Rule wizard, select User and After Creating a User.
  3. On the 3rd step, add the Execute Custom Command action and click Select.
  4. Select the Custom Command you need.

To launch a Custom Command from a script, you need to use the ExecuteCustomCommand method exposed by the object for which you want to execute the Command. To execute a Custom Command on a target object of a Business Rule, Custom Command or Scheduled Task, you need to use the built-in $Context variable, for example:

$target = $Context.BindToObjectEx($Context.TargetObject.AdsPath, $true)

$customCommandId is the ID of a Custom Command. For information on how to get it, see the following SDK article: http://www.adaxes.com/sdk/?HowDoI.GetCu ... andID.html.

Related questions

0 votes
1 answer

I would like to add the following logic into a Powershell script that will be triggered on 'After Create User'. Read the value of the 'title' property of the user just created ... 'True' or 'False'. Could you assist with how to script this please? Many thanks.

asked May 1, 2020 by Bernie (310 points)
0 votes
1 answer

Hi In which sequence are Business Rules executed, when an object is covered by more than one Business Rule Scope ? I have done some tests, which indikated a top-down approach ... Rule 1 (then) Business Rule 2 (then) Business Rule 3 - Thanks and Merry Christmas

asked Dec 20, 2018 by Boxx.dk (2.6k points)
0 votes
1 answer

Hi, I followed this example: https://www.adaxes.com/sdk/IAdmTop6.html, but because the Custom Command is disabled, I get the following error message: System.Management.Automation ... if I enable the Custom Command. I am using Adaxes 2018.2 Best Regards Martin

asked Feb 19, 2020 by Martin (50 points)
0 votes
1 answer

Hi Support, I would like to run a program on a remote server. I'm trying the follow: Import-Module Adaxes Enter-PSSession-ComputerName S254-020ada1 'C: \ Program ... \ schemusc.exe-config Burkhalter' Unfortunately this does not work. Can you help me there?

asked May 14, 2014 by Napoleon (700 points)
0 votes
1 answer

Let's say I have a Business Rule that is fired prior to adding members to a group. Is it possible to get the number of objects being added to that group as ... that tells me that 6 objects will be added or is each added user treated completely independently?

asked Apr 20 by ngb (90 points)
2,797 questions
2,530 answers
57,501 users