The scripts update properties of the target user with the corresponding default values from property patterns. To execute the script, create a custom command, scheduled task or business rule 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 - Specifies LDAP names of the properties to be updated by the script.
- $patternDN - Specifies 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 LDAP 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()