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

时间:2015-01-16 12:03:14

标签: vb.net active-directory exchange-server-2010

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

有人可以通过相同的程序给我指点如何在我们的Exchange2010服务器上启用这些群组邮件吗?

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

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

1 个答案:

答案 0 :(得分:1)

Private Sub 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