Creating a Group in a Hosted Organization
Creating a Group in a Hosted Organization
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
The following example creates a group in the specified hosted organization.
Visual Basic
'////////////////////////////////////////////////////////////////////// ' Function: createGroup() ' Purpose: Creates a group in the specified hosted org. ' ' Input: szDomainName: Domain of the exchange org ' szAlias: Alias of group to add ' szSMTPAddress: SMTP address of org ' szHostingOrgName: Name of hosting container ' szOrganizationalUnit: Name of hosting organization ' szUserName: Admin username ' szUserPwd: Admin pwd ' szDirectoryServer: Name of the Directory Server ' ' Output: createGroup: Contains Error code (if any) ' ' Note: In order for this example to function correctly, it may be necessary to include ' references to the following libraries: Active DS Type Library, Microsoft CDO for ' Exchange Management Library, Microsoft Cluster Service Automation Classes, ' Microsoft CDO for Windows 2000 Library. '////////////////////////////////////////////////////////////////////// Public Function createGroup(ByVal szDomainName As String, _ ByVal szAlias As String, _ ByVal szSMTPAddress As String, _ ByVal szHostingOrgName As String, _ ByVal szOrganizationalUnit As String, _ ByVal szUserName As String, _ ByVal szUserPwd As String, _ ByVal szDirectoryServer) As Integer Dim szConnString As String Dim objGrp As IADs Dim objOrg As IADsContainer Dim objLdap As IADsOpenDSObject Dim objRecipient As cdoexm.IMailRecipient Dim szaMailNickname() As String Dim szaDomTokens() As String Dim szDomainDN As String Dim szLdapDomain As String On Error GoTo errhandler ' Puts the domain specified into an ldap domain string. szaDomTokens = Split(szDomainName, ".", -1, 1) szDomainDN = Join(szaDomTokens, ",dc=") szDomainDN = "dc=" & szDomainDN szLdapDomain = szDomainDN ' Build the ldap path for the hosted organization container. szConnString = "LDAP://" + szDirectoryServer + "/OU=" + _ szOrganizationalUnit + ",OU=" + szHostingOrgName + _ "," + szLdapDomain ' Create the group. Set objLdap = GetObject("LDAP:") Set objOrg = objLdap.OpenDSObject(szConnString, _ szUserName, _ szUserPwd, _ ADS_SECURE_AUTHENTICATION) Set objGrp = objOrg.Create("group", _ "cn=" + szAlias + "@" + szSMTPAddress) With objGrp .Put "samAccountName", szAlias + "@" + szSMTPAddress .Put "groupType", &H80000008 .Put "description", szHostingOrgName + " " + szAlias + "@" + szSMTPAddress + " universal security group" .Put "mailNickname", szAlias .SetInfo End With ' Mail enable the group. Set objRecipient = objGrp objRecipient.MailEnable objGrp.SetInfo createGroup = 0 ' Clean up. Set objGrp = Nothing Set objOrg = Nothing Set objRecipient = Nothing Set objLdap = Nothing Exit Function ' Error handling. errhandler: createGroup = 1 ' Implement error logging here. Set objGrp = Nothing Set objOrg = Nothing Set objRecipient = Nothing Set objLdap = Nothing End Function
Send us your feedback about the Microsoft Exchange Server 2003 SDK.
Build: June 2007 (2007.618.1)
© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.