Hello,
You can use the below script. It should be execute in Windows PowerShell. When prompted, specify the credentials of the Adaxes service account. In the script:
- $serviceHost - the host name of the computer where Adaxes service is installed.
- $sourceRuleDN - the distinguished name (DN) of the business rule to copy actions/conditions from. For details on how to get an object DN, see https://adaxes.com/sdk/HowDoI.GetDnOfObject.
- $targetRuleDN - the distinguished name (DN) of the business rule to copy actions/conditions to.
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$serviceHost = "localhost"
$sourceRuleDN = "CN=After create user,CN=User,CN=Business Rules,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$targetRuleDN = "CN=After update user,CN=User,CN=Business Rules,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly($serviceHost)
# Prompt for credentials.
$credential = Get-Credential
$sourceRule = $service.OpenObject("Adaxes://$sourceRuleDN", $credential.UserName, $credential.GetNetworkCredential().Password, 0)
$targetRule = $service.OpenObject("Adaxes://$targetRuleDN", $credential.UserName, $credential.GetNetworkCredential().Password, 0)
# 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)
}