Create an Active Directory Group using C#

by Brad 30. October 2007 09:35
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."

Tags:

C#

Comments

9/3/2008 7:21:26 AM #

What are "-2147483644" ????

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

Kuldeep Kadyan

Kuldeep Kadyan |

11/9/2009 6:04:52 AM #

Universal = -2147483640,
        Global= -2147483646,
        DomainLocal= -2147483644

Mohamed Osman |

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar