Script repository

Add allowed property value to a property pattern

Updated on: Jan 18, 2026, Views: 6780

Property validation

The script adds a new value to the list of values allowed for a property by a property pattern and sorts all the values in alphabetical order. To execute the script, create a custom command configured for the Domain object type. The new value is taken from the command parameter.

Parameters

  • $propertyName - the name of the property to add allowed value for.
  • $propertyPatternDN - the distinguished name (DN) of the property pattern to update. For information on how to get the DN of a directory object, see Get the DN of a directory object.
  • $parameterName - the name of the custom command parameter that will be used to enter the value to be added. The name must include the param- prefix.
$propertyName = "company" # TODO: modify me
$propertyPatternDN = "CN=Germany pattern,CN=Property Patterns,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$parameterName = "param-Value" # TODO: modify me

# Get parameter value
$parameterValue = $Context.GetParameterValue($parameterName)

# Bind to the property pattern
$propertyPattern = $Context.BindToObject("Adaxes://$propertyPatternDN")

# Get existing values
$values = New-Object System.Collections.ArrayList
$isPropertyRequired = $False
foreach ($item in $propertyPattern.Items)
{
    if ($item.PropertyName -ne $propertyName)
    {
        continue
    }
    
    $constraints =  $item.GetConstraints()
    try
    {
        $constraint = $constraints.GetConstraint("ADM_PROPERTYCONSTRAINTCATEGORY_VALUEFORMAT")
    }
    catch
    {
        $Context.LogMessage("No allowed values specified for property $propertyName.", "Warning")
        return
    }
    
    # Check if new value exists
    if ($constraint.Values -contains $parameterValue)
    {
        return
    }

    # Get current values
    $constraint.Values | %%{[void]$values.Add($_)}
    $isPropertyRequired = $item.IsPropertyRequired
    
    # Remove property pattern item
    $propertyPattern.Items.Remove($item)
    break
}

# Add new value
[void]$values.Add($parameterValue)

# Sort values
$values.Sort()

# Update property pattern
$item = $propertyPattern.Items.Create()
$item.PropertyName = $propertyName
$item.IsPropertyRequired = $isPropertyRequired

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

# Save the changes
$item.SetInfo()
$propertyPattern.Items.Add($item)

Comments 0

You must be signed in to comment.

    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.