SummaryI had a hard time discovering this solution and wanted to post in hopes to help someone else. At my first attempt at finding a solution, all I could find was people saying it was impossible with just writing to Active Directory. So for awhile I was heading down the path of creating the contact using DirectoryServices then using remote powershell commands against the exchange server to mail enable the contacts and distribution lists. I eventually abandoned that approach and went back to finding a way with only using DirectoryServices.
If you don’t care about the code and just want attributes, here are the email attributes that were set when everything started working.
- reportToOriginator = TRUE (for distribution lists) Add this, it is not in the code blocks.
Server 2008 R2 (Active Directory)
Visual Studio 2012
CodeImports System.DirectoryServices / using System.DirectoryServices;
Create Contact in VB
Create Contact in C# (I can not verify this code, I just used a converter)
Create Distribution List in VB
Create Distribution List in C# (I can not verify this code, I just used a converter)
One last bit of info
After you create a contact or distribution list it will not show up on the Global Address List until the scheduled update, probably over night. If you want to force an update you must run the following powershell command on the Exchange server.
Get-GlobalAddressList | Update-GlobalAddressList