c#-4.0 - 如何在 C# 中使用 LDAP 在 Active Directory 中添加新组

标签 c#-4.0 active-directory ldap

我有使用 LDAP 和 C# 在 Active Directory 中创建新组的场景。

请提供建议

最佳答案

CodeProject 上的这篇文章是一个非常好的起点:

Howto: (Almost) Everything In Active Directory via C#

要创建组,您需要:

  • 绑定(bind)到要在
  • 内创建组的容器
  • 创建组并定义一些属性

  • 代码:
    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/

    相关文章:

    .net - VS2012 .NET 4.0 Clickonce VSTO CryptographicException : SignatureDescription could not be created for the signature algorithm supplied

    c# - 为什么在泛型类中使用重复嵌套类型的字段声明会导致大量源代码增加?

    xml - 在 C# 中创建 MS Project XML 文件

    active-directory - UserPrincipal 相当于 DirectoryEntry.Invoke?

    php - 使用 SSL 验证 LDAP/Active Directory 登录

    c# - 为什么 IList<T> 没有排序?!?! (编辑)

    java - LDAP 查询未从 Active Directory 返回正确的数据

    java - 连接到 LDAP 时 JNDI 无法正确解码 BASE64 字符串

    java - 将数据从 ORACLE Internet Directory (OID) 复制到 apacheDS LDAP

    c# - 有没有办法通过 UserPrincipal 类设置新用户的域后缀?