Skip to content

Modifying Property Patterns

The following code sample modifies the built-in Property Pattern entitled User Pattern. The script specifies a list of possible values for the Department property of user accounts.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the 'User Pattern' Property Pattern
$propertyPatternsPath = $admService.Backend.GetConfigurationContainerPath(
    "PropertyPatterns")
$propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $propertyPatternsPath
$builtinPathObj = $propertyPatternsPathObj.CreateChildPath("CN=Builtin")
$userPatternPath = $builtinPathObj.CreateChildPath("CN=User Pattern")

$userPattern = $admService.OpenObject($userPatternPath.ToString(),
    $NULL, $NULL, 0)

# Delete the item for the 'Department' property
foreach ($item in $userPattern.Items)
{
    if ($item.PropertyName -ieq "department")
    {
        $userPattern.Items.Remove($item)
        break
    }
}

$item = $userPattern.Items.Create()
$item.PropertyName = "department"

$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
    "ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$constraint.Values = @("IT", "HR", "Sales")
$constraints.Add($constraint)
$item.SetConstraints($constraints)

$item.SetInfo()
$userPattern.Items.Add($item)

See also