Hello,
Here is the updated script.
$propertyName = "company" # TODO: modify me
$propertyPatternDN = "CN=My 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
$userPattern = $Context.BindToObject("Adaxes://$propertyPatternDN")
$values = New-Object System.Collections.ArrayList
$isPropertyRequired = $False
foreach ($item in $userPattern.Items)
{
if ($item.PropertyName -ne $propertyName)
{
continue
}
$constraints = $item.GetConstraints()
$constraint = $constraints.GetConstraint("ADM_PROPERTYCONSTRAINTCATEGORY_VALUEFORMAT")
# Check if new value exists
if ($constraint.Values -notcontains $parameterValue)
{
return
}
# Get current values
$constraint.Values | %%{[void]$values.Add($_)}
$isPropertyRequired = $item.IsPropertyRequired
# Remove Property Pattern item
$userPattern.Items.Remove($item)
break
}
# Add new value
[void]$values.Remove($parameterValue)
# Sort values
$values.Sort()
# Update Property Pattern
$item = $userPattern.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()
$userPattern.Items.Add($item)