Modifying property patterns

The following code sample modifies a built-in property pattern, User. 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
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the property pattern
$propertyPatternsPath = $service.Backend.GetConfigurationContainerPath("PropertyPatterns")
$propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $propertyPatternsPath
$builtinPathObj = $propertyPatternsPathObj.CreateChildPath("CN=Builtin")
$userPatternPath = $builtinPathObj.CreateChildPath("CN=User")

$pattern = $service.OpenObject($userPatternPath.ToString(), $null, $null, 0)

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

$item = $pattern.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()
$pattern.Items.Add($item)

The following code sample modifies a built-in property pattern, User. The script specifies the default value for the Web page property of user accounts.

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

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

# Bind to the property pattern
$propertyPatternsPath = $service.Backend.GetConfigurationContainerPath("PropertyPatterns")
$propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $propertyPatternsPath
$builtinPathObj = $propertyPatternsPathObj.CreateChildPath("CN=Builtin")
$userPatternPath = $builtinPathObj.CreateChildPath("CN=User")

$pattern = $service.OpenObject($userPatternPath.ToString(), $null, $null, 0)

# Find the item for the 'Web page' property
$webPageItem = $null
foreach ($item in $pattern.Items)
{
    if ($item.PropertyName -ieq "wWWHomePage")
    {
        $webPageItem = $item
        break
    }
}
# Create a property pattern item if it doesn't exist.
if (-not $webPageItem)
{
    $webPageItem = $pattern.Items.Create()
    $webPageItem.PropertyName = "wWWHomePage"
}

$webPageItem.DefaultValue = "https://www.example.com/Users/%username%/"
$webPageItem.GenerateDefaultValueDuringCreating = $true

# Save the changes.
$webPageItem.SetInfo()
$pattern.Items.Add($webPageItem)

See also