Search code examples
c#.netactive-directoryexchange-server

Programmatically create a Distribution Group in Active Directory


I have a Windows Domain here that runs Exchange 2007, and I need to programmatically create new Mailing Lists.

From what I could gather so far, Exchange mailing lists are just normal AD Groups, so I mainly have to worry about the interaction with AD. I used the System.DirectoryService namespace to query AD, but I'm not sure what the correct way would be to create a Distribution Group here. Especially it has to be mail-enabled and show up in the Outlook address book, so I don't know if I need to invoke some magic to make sure Exchange picks up the new group?

Any pointers?


Solution

  • The magic you need to invoke to make a distribution list for Exchange is PowerShell so you'll need to dive into the wonderful world of cmdlets. ;-)

    You can create a distribution group in Active Directory by using System.DirectoryServices (or more easily if you're on .NET 3.5 through System.DirectoryServices.AccountManagement), add members and so on and then use the Enable-DistributionGroup-cmdlet to mail-enable the group.

    You could also create the groups and mail-enable them at the same time by using the New-DistributionGroup-cmdlet.

    Basically what the PowerShell cmdlets do is to set a bunch of Exchange-attributes on the Active Directory group such as proxyAddresses and so on. You might get away with setting some of these "manually" (ie by using System.DirectoryServices) but chances are you get some of them wrong. The supported (as in Microsoft Support-supported) way is through calling the cmdlets.

    You're probably best off Googling on how to call PowerShell from you .NET program (I haven't found a really good article on it but it's pretty straight-forward once you get the hang of it) - MSDN has a sample and a section to get you started.