How to Programmatically Remove Members from Distribution Lists (251176)



The information in this article applies to:

  • Microsoft Site Server 3.0

This article was previously published under Q251176

SUMMARY

This article describes how to programmatically remove a member from a specific distribution list in Site Server 3.0 Membership Directory using Active Directory Service Interfaces (ADSI) 2.5 and VBScript.

MORE INFORMATION

To remove a member from a distribution list in Site Server 3.0, perform the following steps:
  1. Bind to the Distribution List in which you want to remove the user.
  2. Remove the Distinguished Name (DN) of the user you want to remove from to the Distribution List.
The following code illustrates this procedure:
   Const ADS_ATTR_DELETE = 4

   Dim strDistList, strLdapSrv, strRoot, strMemberPath, strUserCn, _ 
      strUserDn, strDistListDn, strAdmin, strAdminPwd

   strLdapSrv       = "LDAP://localhost:5292"
   strRoot          = "o=Microsoft"
   strMemberPath    = ",ou=Members," + strRoot
   strUserCn        = "cn=JohnDoe"
   strUserDn        = strUserCn + strMemberPath
   strDistListDn    = strLdapSrv + "/" + strRoot + _ 
      "/ou=DistributionLists/cn=KmBriefList"
   strAdmin         = "cn=Administrator,ou=Members," + strRoot
   strAdminPwd      = "password"

   'Bind to the specific Distribution List using Administrator credentials
   Set adsDistList = GetObject("LDAP:")
   Set adsDistList = adsDistList.OpenDSObject(strDistListDn, _ 
      strAdmin, strAdminPwd, CLng(0))

   ' Remove the member from the ones in the distribution list
   adsDistList.PutEx ADS_ATTR_DELETE, "dlMember", Array(strUserDN)

   'Flush the property cache and update the directory
    adsDistList.SetInfo

   'Destroy the objects
    Set adsDistList  = Nothing

REFERENCES

251174 How to Programmatically Add Members to Distribution ListsFor information on Active Directory Service Interfaces version 2.5, go to the following location in the MSDN Online Library:

SDK Documentation / Platform SDK / Networking and Directory Services / Active Directory Service Interfaces


Modification Type:MajorLast Reviewed:2/4/2000
Keywords:kbhowto KB251176 kbAudDeveloper