Script repository

Add user to groups specified in a DN syntax property

Updated on: Jan 18, 2026, Views: 8178

Group membership

The script adds a user to the groups specified in a DN syntax property. To execute the script, create a business rule, custom command or scheduled task configured for the User object type.

$propertyName = "seeAlso" # TODO: modify me

try
{
    # Get group DNs.
    $groupDNs = $Context.TargetObject.GetEx($propertyName)
}
catch
{
    return
}

# 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")
    }
}

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.