我有使用 LDAP 和 C# 在 Active Directory 中创建新组的场景。
请提供建议
最佳答案
CodeProject 上的这篇文章是一个非常好的起点:
Howto: (Almost) Everything In Active Directory via C#
要创建组,您需要:
代码:
public void Create(string ouPath, string name)
{
if (!DirectoryEntry.Exists("LDAP://CN=" + name + "," + 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=" + name, "group");
// set properties
group.Properties["sAmAccountName"].Value = name;
// save group
group.CommitChanges();
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
}
else { Console.WriteLine(path + " already exists"); }
}
关于c#-4.0 - 如何在 C# 中使用 LDAP 在 Active Directory 中添加新组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16171731/