Script repository

Add or remove object from group upon adding or removing it from another group

Updated on: Jan 18, 2026, Views: 9805

Group membership

The script adds or removes objects from a specific group upon adding or removing them from another group. To execute the script, create a business rule triggering After adding or removing a member from a group. An object will be added or removed from the group specified in the script when added or removed from one of the groups in the Activity Scope of the rule.

In the script, the $targetGroupDN variable specifies the distinguished name (DN) of the group to add or remove members from. For information on how to get an object DN, see Get the DN of a directory object.

$targetGroupDN = "CN=Resources,OU=Groups,DC=example,DC=com" # TODO: modify me

$group = $Context.BindToObjectEx("Adaxes://$targetGroupDN", $True)
if (($Context.Action.IsOperationOfType($Context.TargetObject, "remove group members")) -and
    ($group.IsMember("Adaxes://%member%")))
{
    $group.Remove("Adaxes://%member%")
}
elseif (($Context.Action.IsOperationOfType($Context.TargetObject, "add group members")) -and (-not ($group.IsMember("Adaxes://%member%"))))
{
    $group.Add("Adaxes://%member%")
}

Comments 2

You must be signed in to comment.

  • Michel

    Michel

    Had a problem with the script that when I removed one member which was not member of the target group, it was added to the group.
    Change the line with elseif to avoid this:

    elseif (($Context.Action.IsOperationOfType($Context.TargetObject, "add group members")) -and (-not ($group.IsMember("Adaxes://%member%"))))
    
    • Support

      Support

      Hello,

      Thank you for pointing out the issue. We have updated the script accordingly.

Got questions?

Support Questions & Answers

We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.