.comment-link {margin-left:.6em;}
Books & Articles I wrote.

Wednesday, February 08, 2006


Adding to Groups in ADAM

In ADAM there are a few ways you can add a user to a group. The simplest is just to get an instance of the DirectoryEntry for that group and add the user to the "member" property as follows:

//get a group instance
DirectoryEntry groupEntry = new DirectoryEntry("LDAP://"
+ LdapMachineName
+ ":"
+ LdapPort
+ LdapPartition
+ LdapReadersGroup,

//find the user we are talking of
DirectoryEntry duser = root.Children.Find("CN=steven", "user");

//add the user to the member property of our group

//commit the changes

However, if you wish to do a straight commital, you can use Invoke as follows:

groupEntry.Invoke("Add", new object[] {"LDAP://"
+ LdapMachineName
+ ":"
+ LdapPort
+ "/" + duser.Properties["distinguishedName"].Value.ToString()});

What this does however is to call the IADs Add method via interop. So you can get the same effect as follows:

+ LdapMachineName
+ ":"
+ LdapPort
+ "/" + duser2.Properties["distinguishedName"].Value.ToString());

It's more likely you will use CommitChanges(), but the other techniques can be useful if you wish to quickly update a membership.

This page is powered by Blogger. Isn't yours?

Weblog Commenting and Trackback by HaloScan.com