Here's how to create a Domain Local Group in Active Directory using C#
using (DirectoryEntry myDE =
    new DirectoryEntry(LDAPPath, LDAPUsername, LDAPPassword))
{
   DirectoryEntries myEntries = myDE.Children;
   using (DirectoryEntry group = myEntries.Add("CN=" + Name, "group"))
   {
      group.Properties["sAMAccountName].Add(Name);
      group.Properties["groupType].Add("-2147483644"); //DOMAIN LOCAL GROUP
      group.CommitChanges();
   }
}
Also one thing to note - if the Name ends in a full stop it will fail with a really non-helpful message of "A device attached to the system is not functioning."

Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Tuesday, October 30, 2007 9:35 AM | in C#

Comments

Gravatar
# re: Create an Active Directory Group using C#
Posted by Kuldeep Kadyan
on 9/3/2008 8:21 AM
What are "-2147483644" ????

As i think its group type code. What about other code for groups.

Kuldeep Kadyan

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 3 and 1 and type the answer here: