Add and Remove users from Exchange Distribution Groups programmatically C#

Hi all,

we have a requirement to build an application that has the following functionality:

1) search for exchange distribution group (list).

2) show the members of that group

3) allow the owner of the group to add or delete members

is there a REST api or C# way of doing this?

July 3rd, 2015 8:30am

Exchange distribution group are just AD group. You can manipulate the membership from AD, using ADSI etc.
Free Windows Admin Tool Kit Click here and download it now
July 3rd, 2015 10:48am

If your using Office365 then you use the Graph API vai REST to do that now https://msdn.microsoft.com/en-au/library/azure/hh974478.aspx

If this is on prem there is no REST api to do this at the moment so you

Is your application going to run for users that have administrative rights (or delegated admins) or normal users ?

The ability to allow Group owners to manage members was a feature that was added into exchange/outlook/owa and it relys on the self service roles in RBAC see https://support.microsoft.com/en-us/kb/2586832#/en-us/kb/2586832

In C# you can run the EMS cmdlets like add-distributiongroupmember https://technet.microsoft.com/en-us/library/bb124340(v=exchg.150).aspx in c# via https://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.150).aspx which takes RBAC into account . Or go directly via LDAP using System.Directoryservices https://msdn.microsoft.com/en-us/library/ms180909(v=vs.80).aspx

Cheers
Glen


July 3rd, 2015 6:51pm

Glen,

what about The Exchange Web Services (EWS) Managed API ??

Free Windows Admin Tool Kit Click here and download it now
July 3rd, 2015 7:04pm

If your using Office365 then you use the Graph API vai REST to do that now https://msdn.microsoft.com/en-au/library/azure/hh974478.aspx

If this is on prem there is no REST api to do this at the moment so you

Is your application going to run for users that have administrative rights (or delegated admins) or normal users ?

The ability to allow Group owners to manage members was a feature that was added into exchange/outlook/owa and it relys on the self service roles in RBAC see https://support.microsoft.com/en-us/kb/2586832#/en-us/kb/2586832

In C# you can run the EMS cmdlets like add-distributiongroupmember https://technet.microsoft.com/en-us/library/bb124340(v=exchg.150).aspx in c# via https://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.150).aspx which takes RBAC into account . Or go directly via LDAP using System.Directoryservices https://msdn.microsoft.com/en-us/library/ms180909(v=vs.80).aspx

Cheers
Glen


July 3rd, 2015 10:49pm

If your using Office365 then you use the Graph API vai REST to do that now https://msdn.microsoft.com/en-au/library/azure/hh974478.aspx

If this is on prem there is no REST api to do this at the moment so you

Is your application going to run for users that have administrative rights (or delegated admins) or normal users ?

The ability to allow Group owners to manage members was a feature that was added into exchange/outlook/owa and it relys on the self service roles in RBAC see https://support.microsoft.com/en-us/kb/2586832#/en-us/kb/2586832

In C# you can run the EMS cmdlets like add-distributiongroupmember https://technet.microsoft.com/en-us/library/bb124340(v=exchg.150).aspx in c# via https://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.150).aspx which takes RBAC into account . Or go directly via LDAP using System.Directoryservices https://msdn.microsoft.com/en-us/library/ms180909(v=vs.80).aspx

Cheers
Glen


Free Windows Admin Tool Kit Click here and download it now
July 3rd, 2015 10:49pm

With EWS for searching for Distribution groups this will work but depending on the version your using you may need a workaround. On 2013 you can do it easliy with FindPeople https://msdn.microsoft.com/en-us/library/office/jj191039%28v=exchg.150%29.aspx . In 2010 its a little harder you can do it by nesting all the DL's you want to find in another Group and then use the ExpandDL operation on that to get the member DL's.

For Expanding the members of a group EWS will work fine using the ExpandDL operation https://msdn.microsoft.com/en-us/library/office/dn629392(v=exchg.150).aspx

For managing the members of a Group EWS doesn't have any operations that can be used to do this. (you can manage the members of Contact Groups but these are different from Distribution Lists).

(Personally if you not on o365 and can't use the newer API's i would suggest you frount end the EMS cmdlets with your own REST service, that will give you the most flexabilty in your app especially if your looking to build Modern apps etc).

Cheers
Glen

July 4th, 2015 12:02am

With EWS for searching for Distribution groups this will work but depending on the version your using you may need a workaround. On 2013 you can do it easliy with FindPeople https://msdn.microsoft.com/en-us/library/office/jj191039%28v=exchg.150%29.aspx . In 2010 its a little harder you can do it by nesting all the DL's you want to find in another Group and then use the ExpandDL operation on that to get the member DL's.

For Expanding the members of a group EWS will work fine using the ExpandDL operation https://msdn.microsoft.com/en-us/library/office/dn629392(v=exchg.150).aspx

For managing the members of a Group EWS doesn't have any operations that can be used to do this. (you can manage the members of Contact Groups but these are different from Distribution Lists).

(Personally if you not on o365 and can't use the newer API's i would suggest you frount end the EMS cmdlets with your own REST service, that will give you the most flexabilty in your app especially if your looking to build Modern apps etc).

Cheers
Glen

  • Marked as answer by KFerg 16 hours 38 minutes ago
Free Windows Admin Tool Kit Click here and download it now
July 4th, 2015 3:59am

With EWS for searching for Distribution groups this will work but depending on the version your using you may need a workaround. On 2013 you can do it easliy with FindPeople https://msdn.microsoft.com/en-us/library/office/jj191039%28v=exchg.150%29.aspx . In 2010 its a little harder you can do it by nesting all the DL's you want to find in another Group and then use the ExpandDL operation on that to get the member DL's.

For Expanding the members of a group EWS will work fine using the ExpandDL operation https://msdn.microsoft.com/en-us/library/office/dn629392(v=exchg.150).aspx

For managing the members of a Group EWS doesn't have any operations that can be used to do this. (you can manage the members of Contact Groups but these are different from Distribution Lists).

(Personally if you not on o365 and can't use the newer API's i would suggest you frount end the EMS cmdlets with your own REST service, that will give you the most flexabilty in your app especially if your looking to build Modern apps etc).

Cheers
Glen

  • Marked as answer by KFerg Sunday, July 05, 2015 2:50 PM
July 4th, 2015 3:59am

thanks Glen!

also I've noticed all our Distribution Groups are appearing within active directory.  Another potential option is to use the standard library for working with Active Directory: System.DirectoryServices namespace in the System.DirectoryServices.dll.

for example:

Directory Searcher

adding members

?

Free Windows Admin Tool Kit Click here and download it now
July 5th, 2015 11:03am

LDAP will work find via System.DirectoryService one thing to keep in mind is those classes generally aren't availble in Modern apps if your going that way.

Cheers
Glen

July 6th, 2015 6:56am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics