Script Repository


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

August 30, 2018
889

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

In the following example, objects will be added or removed from the Resources group after adding or removing them from one of the groups located in the Resources OU.

Business Rule configuration

Parameter:

  • $targetGroupDN - specifies the Distinguished Name (DN) of the group to add or remove members from.
Edit Remove
PowerShell
$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 (-not ($group.IsMember("Adaxes://%member%")))
{
    $group.Add("Adaxes://%member%")
}

Comments ( 0 )
No results found.
Leave a comment