Hello,
Thank you for specifying. Please, find the script below. It must be executed in a custom command configured for the Group object type. The script copies membership rules from the group specified in the custom command parameter to the group on which the command is executed. In the script:
- $sourceGroupParameterName – Specifies the name of the directory object picker parameter used to select the source group. The name must start with the param- prefix.
- $addOrReplaceParameterName – Specifies the name of the drop-down list parameter used to specify whether the source group membership rules will be added to the target group, or will replace the existing rules. The name must start with the param- prefix. The parameter must have two items with the following values:

$sourceGroupParameterName = "param-SourceGroup" # TODO: modify me
$addOrReplaceParameterName = "param-AddOrReplace" # TODO: modify me
# Get parameter values
$addOrReplace = $Context.GetParameterValue($addOrReplaceParameterName)
$sourceGroupDN = $Context.GetParameterValue($sourceGroupParameterName)
# Bind to the source group
$sourceGroup = $Context.BindToObjectByDN($sourceGroupDN)
# Check if source group is rule-based
if($sourceGroup.MembershipType -ne "ADM_GROUPMEMBERSHIPTYPE_RULEBASED")
{
$Context.Cancel("The source group is not rule-based")
return
}
# Check if target group is rule-based
if($Context.TargetObject.MembershipType -ne "ADM_GROUPMEMBERSHIPTYPE_RULEBASED")
{
$Context.Cancel("The target group is not rule-based")
return
}
switch ($addOrReplace)
{
"Add"
{
# Get target group membership rules collection
$targetGroupRules = $Context.TargetObject.MembershipRules
# Add source group rules to the collection
foreach($rule in $sourceGroup.MembershipRules)
{
$targetGroupRules.Add($rule)
}
# Update target group membership rules collection
$Context.TargetObject.MembershipRules = $targetGroupRules
}
"Replace"
{
$Context.TargetObject.MembershipRules = $sourceGroup.MembershipRules
}
}
# Save the changes
$Context.TargetObject.SetInfo()