0 votes

Hello Community,

I need, by script to get all Business Rules from a root container with recursive mode.

$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace" $service = $ns.GetServiceDirectly("localhost") $businessRulesPath = $service.Backend.GetConfigurationContainerPath("BusinessRules") $businessRulesContainer = $service.OpenObject("Adaxes://xxx:1251/CN=Service,CN=CustomRootContainer,CN=Business Rules,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes", $null, $null, 0)

$businessRulesContainer return me all object (BU and Container) under CustomRootContainer but I really need to have all object which are in child container.

Someone could help me ? Thank

by (20 points)

1 Answer

0 votes
by (272k points)

Hello,

For example, you can use the below script to generate a report. The report does not need to have a scope or parameters.

$Context.DirectorySearcher.Criteria = New-AdmCriteria "adm-BusinessRule"
$Context.DirectorySearcher.BaseObjectPath = $Context.GetWellKnownContainerPath("businessRules")
$Context.Items.Add($Context.DirectorySearcher)

If the approach does not meet your needs, please, describe the desired behavior in all the possible details with live examples.

0

Hello,

Please, describe the exact desired behavior in all the possible details and we will do our best to provide you with a full script.

0

Hello,

We need a script which liste all business rule from a root container and for each business rule we want to change some parameters

To be clear, in the script below I juste want to render dynamic the variable $containers, currently we need to edit the scipt every time we add/remove a container.

$containers = @(
    "CN=xxx1", 
    "CN=xxx2",
    "CN=xxx3",
    ) 


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

foreach ($container in $containers)
{
    $rules = $service.OpenObject("Adaxes://xxxxx:1251/$container,CN=Business Rules,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes", $null, $null, 0)

    foreach ($rule in $rules)
    {
        #$rule.Name
        if ($rule.Name.StartsWith("CN=Update - "))
        {
            $ExecutionMoment = $rule.ExecutionMoment 
            $ObjectType = $rule.ObjectType
            $OperationType = $rule.OperationType

            if ($ExecutionMoment -ine "ADM_BUSINESSRULEEXECMOMENT_AFTER")
            {
                $rule.ExecutionMoment = "ADM_BUSINESSRULEEXECMOMENT_AFTER"
            }
            if ($ObjectType -ine "user")
            {
                $rule.ObjectType = "user"
            }
            if ($OperationType -ine "set properties")
            {
                $rule.OperationType = "set properties"
            }

            $rule.SetInfo()
        }
    }
}

If you read the history, i put an image which descript the need, I just want to set a variable with "OAIVS" and get all "subtree" BusinessRule.

Let me know if need more details

0

Hello,

Thank you for the provided details. Please find the full script below.

# Search parameters
$rulesContainerPath = $Context.GetWellKnownContainerPath("businessRules")
$searcher = $Context.BindToObject($rulesContainerPath)
$searcher.Criteria = New-AdmCriteria "adm-BusinessRule"
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"

try
{
    # Execute search
    $searchResultIterator = $searcher.ExecuteSearch()
    $searchResults = $searchResultIterator.FetchAll()

    foreach ($searchResult in $searchResults)
    {
        $rule = $Context.BindToObjectBySearchResult($searchResult)
        $ExecutionMoment = $rule.ExecutionMoment 
        $ObjectType = $rule.ObjectType
        $OperationType = $rule.OperationType

        if ($ExecutionMoment -ine "ADM_BUSINESSRULEEXECMOMENT_AFTER")
        {
            $rule.ExecutionMoment = "ADM_BUSINESSRULEEXECMOMENT_AFTER"
        }
        if ($ObjectType -ine "user")
        {
            $rule.ObjectType = "user"
        }
        if ($OperationType -ine "set properties")
        {
            $rule.OperationType = "set properties"
        }

        $rule.SetInfo()
    }
}
finally
{
    # Release resources
    if ($searchResultIterator){ $searchResultIterator.Dispose() }
}
0

Hello,

Thank you for you script it's work ! I profite to ask you if we can copy an existing rule (with all condition and action) to a new one ?

I saw this article but, https://www.adaxes.com/sdk/SampleScripts.CreatingBusinessRuleContainers/ I don't know if we can copy - past an exisitng rule.

Thank you for you response.

0

Hello,

Unfortunately, there is no easy way to do that. You will need to copy not only the rule itself, but also all the actions and conditions in the script. We recommend you to just use the Administration console to copy existing business rules.

Related questions

0 votes
1 answer

In our environment, we have many business rules with "Add to group". Now I have to delete the "Add to group xyz" in all business rules, as the group is now rule-based. Is there ... in Adaxes so that I don't have to search for and delete all "Add to group xyz"?

asked Mar 7 by DRiVSSi (280 points)
0 votes
1 answer

Hello, We have some Create Business Rules with ifs and other actions. Now these have to be controlled by a third person who has no rights to the console. How can I export the ... to a .txt file? The TXT must contain the condition and the actions. Thanks a lot

asked Aug 10, 2023 by DRiVSSi (280 points)
0 votes
1 answer

I'd like to be able to either send an email report or export a CSV of all of the business rules carried out when a user is disabled. This would be ... Management Activity section but this includes things that weren't part of the disable operation. Thanks

asked Feb 19, 2020 by bavery (250 points)
0 votes
1 answer

Hi, might be a stupid question, but how are actions executed within a business like these here: Is every action only executed if the previous action succeeded or each time a ... .o I thought they will be executed in order and depends each on the previous one

asked Jun 5, 2023 by wintec01 (1.1k points)
0 votes
1 answer

Hi, our user objects are synced from HR system into AD and generated by a middleware - would a business rule "After creating a user" be triggered in this way or not? Looks ... for this? I need to control those tasks and would like to exit in case of issues

asked Jun 5, 2023 by wintec01 (1.1k points)
3,351 questions
3,052 answers
7,791 comments
545,102 users