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
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")
# Bind to the business rule
$businessRulesPath = $service.Backend.GetConfigurationContainerPath(
"BusinessRules")
$businessRulesPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
$businessRulesPath
$myBusinessRuleAdsPath = $businessRulesPathObj.CreateChildPath( `
"CN=My Rule")
$rule = $service.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
- Managing business rules
- Binding to Adaxes-specific objects
- Managing Adaxes-specific objects
- IAdmBusinessRule
- IAdmCollection
- Online script repository