Hello,
Your approach cannot be used in the UI as the values must be entered directly in the script. In this case, it is probably easier to just use the Administration console to add the required values. Also, your script will make a lot of extra work including the binding to the property pattern separately for each value in the predefined array. If that is the approach you want to use, here is the updated script that will do the trick.
$propertyName = "company" # TODO: modify me
$propertyPatternDN = "CN=My Pattern,CN=Property Patterns,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$valuesToAdd = @("value1", "value2")
# Form new values list
$values = New-Object System.Collections.ArrayList
foreach ($valueToAdd in $valuesToAdd)
{
[void]$values.Add($valueToAdd)
}
# Bind to the Property Pattern
$userPattern = $Context.BindToObject("Adaxes://$propertyPatternDN")
$isPropertyRequired = $False
foreach ($item in $userPattern.Items)
{
if ($item.PropertyName -ne $propertyName)
{
continue
}
$constraints = $item.GetConstraints()
$constraint = $constraints.GetConstraint("ADM_PROPERTYCONSTRAINTCATEGORY_VALUEFORMAT")
# Get current values
$constraint.Values | Where-Object { $values -notcontains $_ } | %%{[void]$values.Add($_)}
$isPropertyRequired = $item.IsPropertyRequired
# Remove Property Pattern item
$userPattern.Items.Remove($item)
break
}
# 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)