|
In my previous posts about LDAP group membership, I've talked about how to get a list of groups, how to search for a particular groups members, and how to search for what groups a particular user belongs to. Up next: how to change group membership.
To add or remove a user from a group, you need to modify the "member" attribute of the group itself. To do this we'll use the set-ldap cmdlet of NetCmdlets.
Add a user to a group:
To add a user to a group, set the DN parameter of set-ldap to the DN of the group itself. Then use the -addattribute flag to tell the cmdlet to add the attribute specified by -attrtype and -attrvalue. -Attrtype in this case will be "member", and -AttrValue will be the DN of the user you want to add to the group. So to add myself to the Administrators group:
Now that I've been added to the group, if I do another search for all the groups that I am a member of, I'll see "Administrators" in the list now:
Remove a user from a group:
Removing a user from a group is the same process - except instead of using the -addattribute flag of the set-ldap cmdlet, I'll use -deleteattribute:
Now that "CN=Lance Robinson" has been removed from the member attribute of the group itself, I am no longer a member of the Administrators group:
|