title: LDAP: How to add a new user to a group inside an OU
body: <p>I have some code using <code>DirectoryEntry</code> to manipulate the local Active Directory via LDAP. Currently I find a specific <code>OU</code>, add a user to it, update the properties of the user and then commit all changes:</p>
  
  <pre><code>DirectoryEntry ldapRoot = new DirectoryEntry(ldapString, user, password);
  DirectoryEntry userGroup = ldapRoot.Children.Find("OU=OUGroup");
  DirectoryEntry newUser = userGroup.Children.Add("CN=" + userName, "user");
  newUser.Properties["displayName"].Value = displayName;
  
  ...
  
  newUser.CommitChanges();
  userGroup.Close();
  ldapRoot.Close();
  </code></pre>
  
  <p>ldapString is something akin to <code>LDAP:\\DC=company,DC=local</code>, basically it's just fetching the root entry.</p>
  
  <p>I change several Properties, but it's all working fine. However, I have another <code>OU</code> called SharePoint_Groups, which has a group inside called <code>Internal</code>. I want to add the new user as a member of this group, but I'm at a loss of how to do it. I tried the following:</p>
  
  <pre><code>DirectoryEntry spGroup = ldapRoot.Children.Find("OU=Sharepoint_Groups");
  DirectoryEntry internal = spGroup.Children.Find("CN=Internal");
  </code></pre>
  
  <p>It does not work and I am not sure how I should address <code>Internal</code> - is CN= correct or should I use some other specification?</p>
  
  <p>And, once I have the correct group, how do I add the existing user to it?</p>
  
  <p>Thanks in advance</p>