Group Object in Active Directory

Description :


We can create a Group Object in Active Directory.

Following are the namespaces used


using System.DirectoryServices;
using System.Reflection;


 
public class ADGroup
{

private String ADGRPOUP = "group";

enum GrpType : uint
{
UnivGrp = 0x08,
DomLocalGrp = 0x04,
GlobalGrp = 0x02,
SecurityGrp = 0x80000000
}

DirectoryEntry MyDirectoryEntry = new DirectoryEntry("LDAP://RootDSE");
String Mystr = (String) MyDirectoryEntry.Properties["defaultNamingContext"][0];
MydeAD = new DirectoryEntry("LDAP://" + Mystr);
GrpType Mygt = GrpType.GlobalGrp | GrpType.SecurityGrp;
int MytypeNum = (int)Mygt;
DirectoryEntry Myou = MydeAD.Children.Find("OU=Users");
DirectoryEntry Mygroup = Myou.Children.Add("cn=myGroupName", ADGRPOUP );
Mygroup.Properties["sAMAccountName"].Add("myGroupName");
Mygroup.Properties["description"].Add(" description myGroupName");
Mygroup.Properties["groupType"].Add(typeNum);
Mygroup.CommitChanges();
}



By
Nathan


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: