将邮件联系人添加到 AD 中

Gra*_*ins 2 c# active-directory

我正在寻找有关如何在 AD 中创建邮件联系人的一些指南。这是SO Q#1861336的后续问题。

我想要做的是将大量联系人对象添加到 Active Directory 中的 OU 中。我一直在使用CodeProject上的示例,但是它们仅展​​示如何创建新用户等。

如何使用 C# 创建联系人?它是否类似于创建新用户但具有不同的 LDAP 类型属性?

我的计划是然后运行enable-mailcontact cmdlet powershell 脚本以使Exchange 2010 能够查看GAL 中的联系人。

正如您从我的问题中看到的,我通常不处理 c# 或 Active Directory,因此在我开始使用这把装满子弹的枪之前,任何帮助/指针都会非常有用。

谢谢,

授予

Dat*_*ase 5

与创建用户类似

只是我们“联系人”而不是“用户”作为对象

这是一个脏代码(未经测试)

public string CreateContact(string ldapPath, string userName, 
    string userEmail)
{
    string oGUID = string.Empty;
    try
    {            
        string connectionPrefix = "LDAP://" + ldapPath;
        DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
        DirectoryEntry newUser = dirEntry.Children.Add
            ("CN=" + userName, "contact");
        newUser.Properties["DisplayName"].Value = userName;

        //important attributs are
        newUser.Properties["targetAddress"].Value = "SMTP:" + userEmail;
        newUser.Properties["mailNickname"].Value = userName;

        // I'm still trying to figureout what shoud I use here!
        newUser.Properties["showInAddressBook"].Value = ???;

        newUser.CommitChanges();
        oGUID = newUser.Guid.ToString();
        dirEntry.Close();
        newUser.Close();
    }
    catch (System.DirectoryServices.DirectoryServicesCOMException E)
    {
        //DoSomethingwith --> E.Message.ToString();
        //MessageBox.Show(E.Message);    
    }
    return oGUID;
}
Run Code Online (Sandbox Code Playgroud)

希望对你有帮助