Script repository

All business rules, custom commands and scheduled tasks executing a specific custom command

Updated on: Jan 18, 2026, Views: 4035

Export data

The script creates a CSV file containing all business rules, custom commands and scheduled tasks executing the specified custom command. To execute the script, create a scheduled task configured for the Domain object type and add a managed domain to the Activity Scope of the task. The domain will only be used to trigger execution of the scheduled task.

Parameters

  • $customCommandID - the identifier of the custom command to search for. For information on how to get the identifier, see Get custom command identifier.
  • $csvFilePath - the path to the file that will contain the script results.
$customCommandID = "{9DB88EC3-1241-4AB1-9612-C7C982BAA49F}" # TODO: modify me
$csvFilePath = "C:ScriptsReport.csv" # TODO: modify me

function IsActionFound ($actions, $customCommandID)
{
    foreach ($action in $actions)
    {
        if ($action.Class -ne "adm-CustomCommandAction")
        {
            continue
        }
        
        $customCommandAction = $action.GetAction()
        if ($customCommandAction.CustomCommandId -ne $customCommandID)
        {
            continue
        }
        
        return $True
    }
    
    return $False
}

function IsContainsExecuteCommandAction ($configurationObject, $customCommandID)
{
    for ($i = 0; $i -lt $configurationObject.ConditionedActions.Count; $i++)
    {
        $conditionedActions = $configurationObject.ConditionedActions.GetObject($i)
        
        if (IsActionFound $conditionedActions.Actions $customCommandID)
        {
            return $True
        }
        elseif (IsActionFound $conditionedActions.ElseActions $customCommandID)
        {
            return $True
        }
        else
        {
            for ($j = 0; $j -lt $conditionedActions.ElseIfConditionedActions.Count; $j++)
            {
                $elseIfConditionedActions = $conditionedActions.ElseIfConditionedActions.GetObject($j)
                if (IsActionFound $elseIfConditionedActions.Actions $customCommandID)
                {
                    return $True
                }
            }
        }
    }
    
    return $False
}

$configurationContainersToObjectTypes = @{
    "CustomCommands" = "adm-CustomCommand";
    "BusinessRules" = "adm-BusinessRule";
    "ScheduledTasks" = "adm-ScheduledTask";
}

$records = New-Object System.Collections.ArrayList
foreach ($item in $configurationContainersToObjectTypes.GetEnumerator())
{
    # Search configuration objects.
    $path = $Context.GetWellKnownContainerPath($item.Key)
    $searcher = $Context.BindToObject($path)
    $criteria = New-AdmCriteria $item.Value
    $searcher.Criteria = $criteria
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.PageSize = 500

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

        # Search 'Execute Custom Command' action.
        foreach ($searchResult in $searchResults)
        {
            $configurationObject = $Context.BindToObjectBySearchResult($searchResult)
            if (IsContainsExecuteCommandAction $configurationObject $customCommandID)
            {
                $record = New-Object PSObject
                $record | Add-Member -MemberType NoteProperty -Name Name -Value $configurationObject.Get("name")
                $record | Add-Member -MemberType NoteProperty -Name Path -Value $configurationObject.AdsPath
                $records.Add($record)
            }
        }
    }
    finally
    {
        # Release resources
        $searchResultIterator.Dispose()
    }
}

$records | Export-Csv -Path $csvFilePath -NoTypeInformation

Comments 2

You must be signed in to comment.

  • Olegs

    Olegs

    Hi!
    Seems there is mistake in loop

    for ($j = 0; $j -lt $conditionedActions.ElseIfConditionedActions.Count; $j++)  
    {  
      $elseIfConditionedActions = $conditionedActions.ElseIfConditionedActions.GetObject($i)  
      if (IsActionFound $elseIfConditionedActions.Actions $customCommandID)  
    

    You should use $J instead of $i in "For $elseIfConditionedActions = $conditionedActions.ElseIfConditionedActions.GetObject($i)"

    • Support

      Support

      Hello Olegs,

      Thank you for pointing out the issue. We updated the script accordingly.

Got questions?

Support Questions & Answers

We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.