Defining the scope of activity for a business rule

The following code sample makes a business rule effective for all objects in all the domains managed by Adaxes.

[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
$myRuleAdsPath = $businessRulesPathObj.CreateChildPath( `
    "CN=My Rule")
$rule = $service.OpenObject($myRuleAdsPath, $null, $null, 0)

$scopeItem = $rule.ActivityScopeItems.Create()
$scopeItem.BaseObject = $null
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_ALL_DIRECTORY"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $False
$scopeItem.SetInfo()

$rule.ActivityScopeItems.Add($scopeItem)

The following code sample makes a business rule effective for all objects in a specific domain.

[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)

$domain = "example.com"
$domainObj = $service.OpenObject("Adaxes://$domain", $null, $null, 0)

$scopeItem = $rule.ActivityScopeItems.Create()
$scopeItem.BaseObject = $domainObj
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_CONTAINER"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $False
$scopeItem.SetInfo()

$rule.ActivityScopeItems.Add($scopeItem)

The following code sample makes a business rule effective for all objects located in an Organizational Unit.

[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)

$ouDN = "OU=Sales,DC=domain,DC=com"
$ou = $service.OpenObject("Adaxes://$ouDN", $null, $null, 0)

$scopeItem = $rule.ActivityScopeItems.Create()
$scopeItem.BaseObject = $ou
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_CONTAINER"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $False
$scopeItem.SetInfo()

$rule.ActivityScopeItems.Add($scopeItem)

The following code sample makes a business rule effective for all members of a specific group.

[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)

$groupDN = "CN=My Group,DC=domain,DC=com"
$groupObj = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0)

$scopeItem = $rule.ActivityScopeItems.Create()
$scopeItem.BaseObject = $groupObj
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_GROUP"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $False
$scopeItem.SetInfo()

$rule.ActivityScopeItems.Add($scopeItem)

The following code sample makes a business rule effective for all members of a specific business unit.

[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)

$businessUnitsPath = $service.Backend.GetConfigurationContainerPath( `
    "BusinessUnits")
$businessUnitsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $businessUnitsPath
$myBusinessUnitPath = $businessUnitsPathObj.CreateChildPath( `
    "CN=My BusinessUnit")

$businessUnitObj = $service.OpenObject($myBusinessUnitPath, $null, $null, 0)

$scopeItem = $rule.ActivityScopeItems.Create()
$scopeItem.BaseObject = $businessUnitObj
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_BUSINESSUNIT"
$scopeItem.Inheritance = "ADS_SCOPE_SUBTREE"
$scopeItem.Exclude = $False
$scopeItem.SetInfo()

$rule.ActivityScopeItems.Add($scopeItem)

The following code sample makes a business rule effective for a specific directory object.

[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)

$ouDN = "OU=Sales,DC=domain,DC=com"
$ouObj = $service.OpenObject("Adaxes://$ouDN", $null, $null, 0)

$scopeItem = $rule.ActivityScopeItems.Create()
$scopeItem.BaseObject = $ouObj
$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_CONTAINER"
$scopeItem.Inheritance = "ADS_SCOPE_BASE"
$scopeItem.Exclude = $False
$scopeItem.SetInfo()

$rule.ActivityScopeItems.Add($scopeItem)

See also