0 votes

I have a dropdown-field on the web surface, which is populated by a script. The script looks up all groups in a specific OU and displays them. In the Property Pattern all groups are displayed in alphabetical order. image.png

But on the web portal the groups are shown in a random order.

image.png

What should i do to show the groups in alphabetical order in the portal?

by (250 points)

1 Answer

0 votes
by (185k points)

Hello,

The thing is that the script adds values to the Property Pattern is the order groups are found during the search and when you open editing of the setting, it gets automatically sorted. If you refresh the Web Interface page after that, you will also see sorted values. Unfortunately, there is no possibility to change the behavior. To achieve the desired sorting, you can sort the values in the script before adding them to the Property Pattern. If you have issues updating the script, please, post it here or send to us (support[at]adaxes.com) and we will help you.

0

I'm not sure how to update the script. Thanks for your help! The following script is in a custom command which will be executed by a scheduled task every 30 min

$patternName = "Benutzer-Muster" # TODO: modify me
$propertyToUpdate = "extensionAttribute5" # TODO: modify me

function SearchObjects($filter, $containerPath)
{
    $searcher = $Context.BindToObject($containerPath)
    $searcher.SearchFilter = $filter
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"

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

        return ,$searchResults
    }
    finally
    {
        # Release resources
        if ($searchResultIterator){ $searchResultIterator.Dispose() }
    }
}

# Get all groups in the target OU
$groupSearchResults = SearchObjects "(objectCategory=group)" $Context.TargetObject.AdsPath

# Exit if no groups found
if ($groupSearchResults.Length -eq 0)
{
    return
}

# Get group names
$groupNames = New-Object System.Collections.ArrayList
foreach ($searchResult in $groupSearchResults)
{
    $groupNames.Add($searchResult.Properties["name"].Value)
}

# Find Property Pattern
$propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
$patternSearchResults = SearchObjects "(&(objectCategory=adm-PropertyPattern)(name=$patternName))" $propertyPatternsPath

if ($patternSearchResults.Length -gt 1)
{
    $Context.LogMessage("Found more than one Property Pattern with name '$patternName'.", "Warning")
    return
}
if ($patternSearchResults.Length -eq 0)
{
    $Context.LogMessage("Property Pattern '$patternName' does not exist.", "Error")
    return
}

# Bind to the Property Pattern
$pattern = $Context.BindToObject($patternSearchResults[0].AdsPath)

# Delete the pattern item for the property
foreach ($item in $pattern.Items)
{
    if ($item.PropertyName -ieq $propertyToUpdate)
    {
        $pattern.Items.Remove($item)
        break
    }
}

# Create list of values for the property
$item = $pattern.Items.Create()
$item.PropertyName = $propertyToUpdate

$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
    "ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$constraint.Values = $groupNames.ToArray()
$constraints.Add($constraint)
$item.SetConstraints($constraints)

# Update Property Pattern
$item.SetInfo()
$pattern.Items.Add($item)
+1

Hello,

Thank you for the confirmation. Here is the updated script.

$patternName = "Benutzer-Muster" # TODO: modify me
$propertyToUpdate = "extensionAttribute5" # TODO: modify me

function SearchObjects($filter, $containerPath)
{
    $searcher = $Context.BindToObject($containerPath)
    $searcher.SearchFilter = $filter
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"     

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

        return ,$searchResults
    }
    finally
    {
        # Release resources
        if ($searchResultIterator){ $searchResultIterator.Dispose() }
    }
}

# Get all groups in the target OU
$groupSearchResults = SearchObjects "(objectCategory=group)" $Context.TargetObject.AdsPath

# Exit if no groups found
if ($groupSearchResults.Length -eq 0)
{
    return
}

# Get group names
$groupNames = New-Object System.Collections.ArrayList
foreach ($searchResult in $groupSearchResults)
{
    $groupNames.Add($searchResult.Properties["name"].Value)
}

# Find Property Pattern
$propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
$patternSearchResults = SearchObjects "(&(objectCategory=adm-PropertyPattern)(name=$patternName))" $propertyPatternsPath

if ($patternSearchResults.Length -gt 1)
{
    $Context.LogMessage("Found more than one Property Pattern with name '$patternName'.", "Warning")
    return
}
if ($patternSearchResults.Length -eq 0)
{
    $Context.LogMessage("Property Pattern '$patternName' does not exist.", "Error")
    return
}

# Bind to the Property Pattern
$pattern = $Context.BindToObject($patternSearchResults[0].AdsPath)

# Delete the pattern item for the property
foreach ($item in $pattern.Items)
{
    if ($item.PropertyName -ieq $propertyToUpdate)
    {
        $pattern.Items.Remove($item)
        break
    }
}

# Create list of values for the property
$item = $pattern.Items.Create()
$item.PropertyName = $propertyToUpdate

$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
    "ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$groupNames.Sort()
$constraint.Values = $groupNames.ToArray()
$constraints.Add($constraint)
$item.SetConstraints($constraints)

# Update Property Pattern
$item.SetInfo()
$pattern.Items.Add($item)
0

Thanks for your help, works perfect.

Related questions

0 votes
1 answer

Hi, I followed this example: https://www.adaxes.com/sdk/IAdmTop6.html, but because the Custom Command is disabled, I get the following error message: System.Management.Automation ... if I enable the Custom Command. I am using Adaxes 2018.2 Best Regards Martin

asked Feb 19 by Martin (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 by bavery (1.1k points)
0 votes
0 answers

Before Deactivation of an Account on the Webinterface our Help Desk need to change the AD User Description manually. Is it possible to force a manual change before deactivation ?

asked Feb 7 by lv01 (250 points)
0 votes
1 answer

We're trying to setup a new action in our Web interface that runs on User's that are currently in an OU called 'New Starters' that is in all of our domains (An ... no results, There are no other fields we can use that are unique to accounts in those OUs

asked Feb 7 by richarddewis (1.5k points)
0 votes
1 answer

Hi, is there possibility to search some custom string across all powershell script files used in Adaxes? I.e. Custom commands, Scheduled tasks etc I need to find out where is used some PowerShell command to be able to replace it for another one..

asked Apr 27 by KIT (3.1k points)
2,294 questions
2,050 answers
5,586 comments
58,859 users