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.

Script repository

Add user to groups specified in a DN syntax property

February 23, 2021 Views: 2275

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.

Edit Remove
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")
    }
}
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers