Script Repository


Copy allowed property values from property pattern to custom command parameter

February 25, 2021
215

The script replaces values of a custom command drop-down list parameter with allowed property values from a property pattern. To execute the script, create a scheduled task configured for the Domain-DNS object type and add a managed domain to the Activity Scope of the task.

Parameters:

  • $propertyPatternDN - Specifies the distinguished name (DN) of the property pattern the list of allowed values will be copied from. For information on how to get the DN of a directory object, have a look at the following article: https://www.adaxes.com/sdk/HowDoI.GetDnOfObject.
  • $propertyName - Specifies the LDAP name of the property the list of allowed values will be copied from.
  • $customCommandDN - Specifies the distinguished name (DN) of the custom command whose parameter will be updated. For information on how to get the DN of a directory object, have a look at the following article: https://www.adaxes.com/sdk/HowDoI.GetDnOfObject.
  • $parameterName - Specifies the name (with the param- prefix) of the custom command parameter whose allowed values will be updated.

Edit Remove
PowerShell
$propertyName = "Department" # TODO: modify me
$propertyPatternDN = "CN=User Pattern,CN=Builtin,CN=Property Patterns,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$customCommandDN = "CN=Change Department,CN=Custom Commands,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
$parameterName = "param-departmentName" # TOOD: modify me

# Bind to the Property Pattern
$propertyPattern = $Context.BindToObjectByDN($propertyPatternDN)

# Get allowed property values
$values = New-Object System.Collections.ArrayList
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 are specified for the '$propertyName' property in the property pattern.", "Warning")
        return
    }
    
    
    if ($constraint.Type -eq "ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
    {
        # Get allowed values
        $constraint.Values | %%{[void]$values.Add($_)}
    }
    else
    {
        $Context.LogMessage("No allowed values are specified for the '$propertyName' property in the property pattern.", "Warning")
        return
    }
    
}

if ($values.Count -eq 0)
{
    $Context.LogMessage("No constraint is defined for the '$propertyName' property in the property pattern", "Warning")
    return # Property is not defined in the Property Pattern
}

# Get parameter
$customCommand = $Context.BindToObjectByDN($customCommandDN)
$parameters = $customCommand.Parameters
$parameter = $parameters | Where {$_.Name -eq $parameterName}
if ($NULL -eq $parameter)
{
    $Context.LogMessage("Parameter '$parameterName' not found in the custom command.", "Warning")
    return
}

# Update the list of allowed values
$parameterValues = @()
foreach ($value in $values)
{
    $parameterValue = $parameter.CreateValue()
    $parameterValue.Value = $value
    $parameterValues += $parameterValue
}

$parameter.Values = $parameterValues
$customCommand.Parameters = $parameters
$customCommand.SetInfo()

Comments ( 0 )
No results found.
Leave a comment