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

Remove all members from a group and add to another group

February 25, 2021 Views: 1167

The script removes all members from the target group and adds them to another group. To run the script, you can use a custom command, business rule or scheduled task configured for the Group object type. In the script, the $targetGroupDN variable specifies the distinguished name (DN) of the group to which members will be added.

Edit Remove
$targetGroupDN = "CN=MyGroup,OU=Groups,DC=domain,DC=com" # TODO: modify me

# Get source group members
$sourceGroup = $Context.TargetObject
    $memberGuidsBytes = $sourceGroup.GetEx("adm-DirectMembersGuid") 
    return # source group has no members

$targetGroup = $Context.BindToObjectByDN($targetGroupDN)
foreach ($guidBytes in $memberGuidsBytes)
    # Remove member from the source group
    $guid = [Guid]$guidBytes
    if ($targetGroup.IsMember("Adaxes://<GUID=$guid>"))
    # Add member to the target group

Comments 0
Leave a comment

Got questions?

Support Questions & Answers