0 votes

Hi team,

I would like to update allowed values of a property pattern and found this script: https://www.adaxes.com/script-repository/add-new-allowed-property-value-to-a-property-pattern-s585.htm

However this will only work for one new value. How can I add multiple new values? I tried already a foreach around it, but not working properly :/

by (1.5k points)
0

Hello,

How exactly are you going to specify the values? Is it going to be in a custom command parameter? If so, how exactly are the values going to be specified? Please, describe the desired workflow in all the possible details with live examples.

0

Morning,

it is working now, I needed to remove one break command

Here is the script

$propertyName = "adm-CustomAttributeText1"
$propertyPatternDN = "xxxx" 
$namesDomains = @("Value1","Value2")

foreach($parameterValue in $namesDomains) {        
    # 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 -contains $parameterValue) {
            continue
        }

        # Get current values
        $constraint.Values | %%{[void]$values.Add($_)}
        $isPropertyRequired = $item.IsPropertyRequired

        # Remove Property Pattern item
        $userPattern.Items.Remove($item)
    }

    # Add new value
    [void]$values.Add($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)
}

1 Answer

0 votes
by (294k points)

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)
0

Thank you so much for this! Working!

0

One more question. I noticed the "Hint & Help" area is overwritten also and empty after script was excecuted. Can I add this as well via Script?

+1

Hello,

The behavior is expected similarly to the option making the property required. You can retrieve the hint and help tests into variables and then add them to the new property item being created. The following article should be helpful: https://adaxes.com/sdk/IAdmPropertyPatternItem.

0

Thanks, working like a charm now.

Updates script for reference

$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
    $hint = $item.Hint
    $customHelpText = $item.CustomHelpText
    $propertyInfoMode = $item.PropertyInfoMode

    # 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
$item.Hint = $hint
$item.CustomHelpText = $customHelpText
$item.PropertyInfoMode = $propertyInfoMode

$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)

Related questions

0 votes
1 answer

Update group membership based on one property values. I am trying to find a script that resembles "Update group membership based on two property value" but just for one value.

asked Apr 7, 2022 by lee_thomas (20 points)
0 votes
1 answer

Hello, I have trouble understanding the instruction listed here: https://www.adaxes.com/script-repositor ... s-s516.htm What should I put into $propertyForSearch and ... Since Adaxes is not the only system adding new locations to AD. Thank you.

asked Jul 4, 2019 by DLe (760 points)
0 votes
1 answer

Is it possible to update a Propery Pattern using a powershell script? If a new department OU is created, is it possible to automaticly update the User Pattern's Department property to reflect that a new department has been added?

asked Jan 28, 2013 by kjesoo (960 points)
0 votes
1 answer

I'm creating a powershell script to handle all the 'modify user' steps, instead of having them be individual steps in Adaxes. This script runs after we fill out a form. A ... empty parameter considered as either a "tab" or "4 spaces" ? Thanks for your help.

asked Dec 12, 2022 by lw.fa (150 points)
0 votes
1 answer

How do I go about modifying proxy addresses with PowerShell in Adaxes? Do you have an example in the script repository?

asked Jan 20, 2021 by ComputerHabit (790 points)
3,588 questions
3,277 answers
8,303 comments
548,090 users