如何使用 VB.net 通过邮件启用 AD 组

How to Mail Enable an AD Group with VB.net

我在 VB 中编写了一个程序,它使用 GroupPrincipal 创建 Active Directory 组,并在其中填充用户(和/或其他必要的组)。

任何人都可以指导我如何通过相同的程序在我们的 exchange2010 服务器上启用这些组的邮件吗?

我已经看到(在我的 googleing 中)一些你可以在服务器本身上 运行 的 powershell,但我需要我的程序在创建这些组时自动启用它们。

希望有人能让我走上正轨。 皮特

私有子 CreateDistributionList()

    Dim ad As DirectoryEntry

    Dim contacts As DirectoryEntry

    Dim entry As DirectoryEntry



    ' Create a conntaction to Active Directory

    ad = New DirectoryEntry("LDAP://MACHINENAME/DC=DOMAIN,DC=COM", "username", "password")

    ' Find the OU to create the contact in

    contacts = ad.Children.Find("OU=Distrubtion Lists")



    ' Create AD object

    entry = contacts.Children.Add("CN=LastName\, FirstName", "group")



    ' Fill out basic attributes

    entry.Properties("groupType").Value = 8 ' 8 = Universal Group

    entry.Properties("displayName").Value = "Name"

    entry.Properties("sAMAccountName").Value = "Name" ' I don't know if this is required

    entry.Properties("mail").Value = "EmailAddress@Something.com"

    entry.Properties("telephoneNumber").Value = "555-555-5555"

    entry.Properties("description").Value = "description"



    ' The follow attributes I believe to be the ones required for mail enabling

    ' (though I have not testing thoroughly to pinpoint exactly what is required)



    ' SMPT MUST be capitalized

    entry.Properties("targetAddress").Value = "SMTP:EmailAddress@Something.com"

    entry.Properties("proxyAddresses").Value = New Object() {"SMTP:EmailAddress@Something.com"}

    ' To find the legacyExchangeDN, copy value from an existing contact

    entry.Properties("legacyExchangeDN").Value = ""

    ' mailNickName can not have spaces

    entry.Properties("mailNickName").Value = New String("FirstNameLastName").Replace(" ", "")



    ' Commit Changes to Active Directory

    entry.CommitChanges()



    ' Close connections to Active Directory

    entry.Close()

    ad.Close()

End Sub