Script Repository


Add user to groups specified in a DN syntax property

December 04, 2019
252

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 proeprty 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 )
No results found.
Leave a comment