Script repository

Update user properties based on property pattern

Updated on: Jan 18, 2026, Views: 3207

User accounts

The scripts update properties of the target user with the corresponding default values from property patterns. To execute either of the scripts, create a business rule, custom command or scheduled task configured for the User object type.

Script 1: specific property pattern

The script updates property values of the target user with the default values specified for the properties in a predefined property pattern.

Parameters

  • $propertiesToCheck - the names of the properties to be updated by the script.
  • $patternDN - the distinguished name (DN) of the property pattern to obtain property values from. For information on how to get an object DN, see Get the DN of a directory object.
$propertiesToCheck = @("title", "department") # TODO: modify me
$patternDN = "CN=User Pattern,CN=Builtin,CN=Property Patterns,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me

$pattern = $Context.BindToObjectByDN($patternDN)
foreach($item in $pattern.Items)
{
    if ($propertiesToCheck -notcontains $item.PropertyName)
    {
        continue
    }
    
    $Context.TargetObject.Put($item.PropertyName, $item.DefaultValue)
}

# Save changes
$Context.TargetObject.SetInfo()

Script 2: effective property patterns

The script updates property values of the target user with the default values specified for the properties in the property patterns effective for the user. If there are 2 or more property patterns found specifying a default value for the same property, the property will not be updated.

In the script, the $propertiesToCheck variable specifies the names of the properties to be updated.

$propertiesToCheck = @("title", "department") # TODO: modify me

# Get effective property patterns.
$propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
$propertyPatternsContainer = $Context.BindToObject($propertyPatternsPath)
$propertyPatternsGuidsBytes = $propertyPatternsContainer.GetEffectivePropertyPatterns($Context.TargetObject)

# Get default property values.
$propertyToValue = @{}
foreach ($guidBytes in $propertyPatternsGuidsBytes)
{
    $guid = [Guid]$guidBytes
    $pattern = $Context.BindToObject("Adaxes://<GUID=$guid>")
    foreach($item in $pattern.Items)
    {
        if ($propertiesToCheck -notcontains $item.PropertyName)
        {
            continue
        }
        
        if ($NULL -eq $item.DefaultValue)
        {
            continue
        }
        
        if ($propertyToValue.ContainsKey($item.PropertyName))
        {
            if ($NULL -eq $propertyToValue[$item.PropertyName])
            {
                continue
            }
            
            $propertyToValue[$item.PropertyName] = $NULL
        }
        else
        {
            $propertyToValue.Add($item.PropertyName, $item.DefaultValue)
        }
    }
}

# Update the user
foreach($propertyName in $propertyToValue.Keys)
{
    $value = $propertyToValue[$propertyName]
    if ($NULL -eq $value)
    {
        $Context.LogMessage("Found more than one value for property $propertyName", "Warning")
    }
    else
    {
        $Context.TargetObject.Put($propertyName, $value)
    }
}

# Save the changes
$Context.TargetObject.SetInfo()```

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.