Script Repository


Specify list of possible values for a property

February 18, 2021
1360

The script updates the built-in User Pattern with a list of possible values for a certain property.

To import possible values on a scheduled basis, create a scheduled task for the Domain-DNS object type that runs the script, and then include any of your AD domain in the Activity Scope.

To add the script to a custom command or scheduled task, use the Run a program or PowerShell script action.

Parameters:

  • $propertyName - Specifies the LDAP display name of the property.
  • $values - Specifies the possible values.
  • $isPropertyRequired - Specifies whether to mark the property as required.
Edit Remove
PowerShell
$propertyName = "physicalDeliveryOfficeName" # TODO: modify me
$values = @("London Office", "New York Office") # TODO: modify me
$isPropertyRequired = $False # TODO: modify me

# Modify the User Pattern

# Bind to the User Pattern
$propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
$propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $propertyPatternsPath
$builtinPathObj = $propertyPatternsPathObj.CreateChildPath("CN=Builtin")
$userPatternPath = $builtinPathObj.CreateChildPath("CN=User Pattern")
$userPattern = $Context.BindToObject($userPatternPath)

# Check whether an item exists for the specified property
# If it exists, remove it
foreach ($item in $userPattern.Items)
{
    if($item.PropertyName -eq $propertyName)
    {
        $userPattern.Items.Remove($item)
        break
    }
}

# Create a new item with the values for the specified property
$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
$constraints.Add($constraint)
$item.SetConstraints($constraints)
$item.SetInfo()
$userPattern.Items.Add($item)


Comments ( 0 )
No results found.
Leave a comment