Hello,
The thing is that you did not only add the foreach portion and the array for target business rules. You also changed a part of the code that was copying actions and conditions. We updated the script accordingly:
$sourceRuleDN = "CN=After create user,CN=User,CN=Business Rules,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$targetRuleDNs = @(
"CN=After update user1,CN=User,CN=Business Rules,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes",
"CN=After update user2,CN=User,CN=Business Rules,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes",
"CN=After update user3,CN=User,CN=Business Rules,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes"
) # TODO: modify me with multiple target DNs
$sourceRule = $Context.BindToObjectByDNEx($sourceRuleDN, $True)
foreach ($targetRuleDN in $targetRuleDNs)
{
$targetRule = $Context.BindToObjectByDNEx($targetRuleDN, $True)
$targetRule.ConditionedActions.Clear()
# Copy actions and conditions
foreach ($set in $sourceRule.ConditionedActions)
{
# Create a new set of actions and conditions
$actionsAndConditions = $targetRule.ConditionedActions.Create()
$actionsAndConditions.ConditionsLogicalOperation = $set.ConditionsLogicalOperation
$actionsAndConditions.SetInfo()
# Copy conditions
foreach ($condition in $set.Conditions) {
$newCondition = $actionsAndConditions.Conditions.CreateEx($condition.Class)
$newCondition.SetCondition($condition.GetCondition())
$newCondition.SetInfo()
$actionsAndConditions.Conditions.Add($newCondition)
}
# Copy actions
foreach ($action in $set.Actions)
{
$newAction = $actionsAndConditions.Conditions.CreateEx($action.Class)
$newAction.ExecutionOptions = $action.ExecutionOptions
$actionObj = $action.GetAction()
# 'add to group' -> 'remove from group'
if ($actionObj.IsOperationOfType($null, "change membership") -and
$actionObj.ActionType -eq "ADM_CHANGEGROUPMEMBERSHIPACTION_ADD") {
$actionObj.ActionType = "ADM_CHANGEGROUPMEMBERSHIPACTION_REMOVE"
}
$newAction.SetAction($actionObj)
$newAction.SetInfo()
$actionsAndConditions.Actions.Add($newAction)
}
# Add the set to the custom command
$targetRule.ConditionedActions.Add($actionsAndConditions)
}
}