The script adds a user to the groups specified in a DN syntax property of the user. In the script, the $propertyName variable specifies the LDAP name of the property that stores the groups the user should be added to. To run the script, you can use a custom command, business rule or scheduled task configured for the User object type.
PowerShell
$propertyName = "seeAlso" # TODO: modify me
# Get group DNs
try
{
$groupDNs = $Context.TargetObject.GetEx($propertyName)
}
catch
{
return # The property is empty
}
# Add user to groups
foreach ($dn in $groupDNs)
{
try
{
$group = $Context.BindToObjectByDNEx($dn, $True)
$group.Add($Context.TargetObject.AdsPath)
}
catch
{
$Context.LogMessage("An error occurred while adding to group '$dn':" + $_.Exception.Message, "Warning")
}
}