Mailbox-Enabling a User
You can easily mailbox-enable a user with very little code using ADSI and CDOEXM. The following code shows you how to mailbox-enable a single user specified by a known DN:
' This code creates a mailbox for a user. Option Explicit Dim strUserDN, strEmailAddr, objUser ' ------ SCRIPT CONFIGURATION ------ strUserDN = "<UserDN>
" ' e.g. cn=DrAmy,cn=Users,dc=mycorp,dc=com strHomeMDB = "<Home MDB DN>
" ' e.g. CN=Mailbox Store (SERVER),CN=First Storage Group,CN=InformationStore, ' CN=SERVER,CN=Servers,CN=First Administrative Group,CN=Administrative Groups, ' CN=MYCORP,CN=Microsoft Exchange,CN=Services, ' CN=Configuration,DC=mycorp,DC=com" ' ------ END CONFIGURATION --------- Set objUser = GetObject("LDAP://" & strUserDN) objUser.CreateMailBox strHomeMDB objUser.SetInfo( ) WScript.Echo "Successfully mailbox-enabled user."
Tip
Mailbox-enabling a user requires Exchange Data Administrator permissions.
That should all be familiar with the exception of CreateMailBox
. CreateMailBox
is a method of the IMailBoxStore
CDOEXM interface. This method takes a single argument, the LDAP URL of the mail store object, to create the mailbox in. In the background, the specific changes made by the CreateMailBox
method are on the user
object in Active Directory and include changes to the following attributes:
mDBUseDefaults
msExchUserAccountControl
homeMTA
msExchHomeServerName
homeMDB
mailNickname
msExchMailboxGuid
msExchMailboxSecurityDescriptor
legacyExchangeDN
Once all of those ...
Get Active Directory, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.