Skip to content

Replacing actions and conditions of a Business Rule

The following code sample replaces all actions and conditions of a Business Rule with new ones.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to 'My Rule' Business Rule
$businessRulesPath = $admService.Backend.GetConfigurationContainerPath(
    "BusinessRules")
$businessRulesPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $businessRulesPath
$myBusinessRuleAdsPath = $businessRulesPathObj.CreateChildPath( `
    "CN=My Rule")
$rule = $admService.OpenObject($myBusinessRuleAdsPath, $NULL, $NULL, 0)

# Delete old actions and conditions
$rule.ConditionedActions.Clear()

$actionsAndConditions = $rule.ConditionedActions.Create()
$actionsAndConditions.ConditionsLogicalOperation =
    "ADM_LOGICALOPERATION_AND"
$actionsAndConditions.SetInfo()

# If Office equals 'My Office 1'
$condition = $actionsAndConditions.Conditions.CreateEx(
    "adm-AttributeOperatorValueCondition")
$officeCondition = $condition.GetCondition()
$officeCondition.AttributeName = "physicalDeliveryOfficeName" # Office
$officeCondition.ComparisonOperator = "ADM_COMPARISONOPERATOR_EQUAL"
$officeValue = New-Object "Softerra.Adaxes.Adsi.AdsPropertyValue"
$officeValue.PutObjectProperty("ADSTYPE_UNKNOWN", "My Office 1")
$officeCondition.Value = $officeValue
$officeCondition.CaseSensitive = $False
$condition.SetCondition($officeCondition)
$condition.SetInfo()
$actionsAndConditions.Conditions.Add($condition)

# Update City and ZIP/Postal code
$action = $actionsAndConditions.Actions.CreateEx(
    "adm-SetPropertiesAction")
$action.ExecutionOptions = "ADM_ACTIONEXECUTIONOPTIONS_SYNC"
$updateAction = $action.GetAction()

# City
$cityValue = New-Object "Softerra.Adaxes.Adsi.AdsPropertyValue"
$cityValue.PutObjectProperty("ADSTYPE_UNKNOWN", "My City")
$propertyEntry = New-Object "Softerra.Adaxes.Adsi.AdsPropertyEntry"
$propertyEntry.Name = "l" # City
$propertyEntry.ADsType = "ADSTYPE_CASE_IGNORE_STRING"
$propertyEntry.ControlCode = "ADS_PROPERTY_UPDATE"
$propertyEntry.Values =
    @([Softerra.Adaxes.Interop.Adsi.Cache.IADsPropertyValue]$cityValue)
$updateAction.PropertyList.PutPropertyItem($propertyEntry)

# ZIP/Postal code
$postalCodeValue = New-Object "Softerra.Adaxes.Adsi.AdsPropertyValue"
$postalCodeValue.PutObjectProperty("ADSTYPE_UNKNOWN", "12345")
$propertyEntry = New-Object "Softerra.Adaxes.Adsi.AdsPropertyEntry"
$propertyEntry.Name = "postalCode"
$propertyEntry.ADsType = "ADSTYPE_CASE_IGNORE_STRING"
$propertyEntry.ControlCode = "ADS_PROPERTY_UPDATE"
$propertyEntry.Values =
    @([Softerra.Adaxes.Interop.Adsi.Cache.IADsPropertyValue]$postalCodeValue)
$updateAction.PropertyList.PutPropertyItem($propertyEntry)

$action.SetAction($updateAction)
$action.SetInfo()
$actionsAndConditions.Actions.Add($action)

# Add the set to the Business Rule
$rule.ConditionedActions.Add($actionsAndConditions)

See also