我想在一个网站的活动目录中添加一个新的应用程序组。我不知道如何做到这一点,我从网站上复制了一些代码(我不知道这个网址)。我知道还有其他一些类似的问题,但我不明白......
string newGroup = "_app_" +
string ouPath = "OU=Application Groups,OU=Global,OU=Groups,DC="*domain*";
if (!DirectoryEntry.Exists("LDAP://CN=" + newGroup + "," + ouPath))
{
try
{
// bind to the container, e.g. LDAP://cn=Users,dc=...
DirectoryEntry entry = new DirectoryEntry("LDAP://" + ouPath);
// create group entry
DirectoryEntry group = entry.Children.Add("CN=" + newGroup, "group");
// set properties
group.Properties["sAmAccountName"].Value = newGroup;
group.Properties["GroupScope"].Value = "Global";
group.Properties["GroupCategory"].Value = "Security";
group.Properties["-Description"].Value = "SelfService" + System.Security.Principal.WindowsIdentity.GetCurrent().Name;
// save group
group.CommitChanges();
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
}
else { Console.WriteLine(ouPath + " already exists"); }