Create ADSI User and Exchange Mailbox
Hello,
I am trying to automate the account creation process for Active Directory and Exchange 2000 using ADSI and CDOEXM.
Using samples from MSDN an AD user is created however when it fails when I try to create the Exchange mailbox - either with
1) Type mismatch on the 'Set oMailbox = oUser' line
or
2) 'Object doesn't support this property or method' on the 'CreateMailbox' line if the vars are not explicitly declared.
Any comments or suggestions would be most welcome.
Best Regards,
Steven
Code stub:
----------
Private Sub cmdCreate_Click()
Dim oUser As IADsUser
Dim ou As IADsContainer
Dim oMailbox As CDOEXM.IMailboxStore
Dim sLog As String, sMBXStoreDN As String
Dim sLDAPDomain
On Error GoTo errHandler
sLog = "0"
sLDAPDomain = "DC=T,DC=net"
' Create AD User in correct OU
Set ou = GetObject("LDAP://OU=IT,OU=Userids," & sLDAPDomain)
sLog = "1"
Set oUser = ou.Create("user", "CN=" & "s_test1")
sLog = "2"
' Set properties
oUser.Put "samAccountName", "s_test1"
oUser.Put "userPrincipalName", "s_test1"
oUser.SetInfo
' Set password and enable account
oUser.SetPassword "testing123"
oUser.AccountDisabled = False
oUser.SetInfo
sLog = "2b"
' Create Exchange Mailbox
sLog = "3"
Set oMailbox = oUser
sLog = "4"
szStoreName = "Mailbox Store (EXCHANGE1)"
szStorageGroup = "First Storage Group"
szServerName = "EXCHANGE1"
szAdminGroup = "First Administrative Group"
szExchangeOrg = "TNET"
sMBXStoreDN = "LDAP://CN=" & szStoreName & _
",CN=" & szStorageGroup & _
",CN=InformationStore" & _
",CN=" & szServerName & _
",CN=Servers" & _
",CN=" & szAdminGroup & _
",CN=Administrative Groups" & _
",CN=" & szExchangeOrg & _
",CN=Microsoft
Exchange,CN=Services,CN=Configuration," & _
sLDAPDomain
' MsgBox sMBXStoreDN
' MsgBox oMailbox.HomeMDB
oMailbox.CreateMailbox sMBXStoreDN
sLog = "4b"
oUser.SetInfo
sLog = "5"
Exiting:
Set ou = Nothing
Set oUser = Nothing
Set oMailbox = Nothing
Exit Sub
errHandler:
MsgBox Err.Description & " log:" & sLog
GoTo Exiting
End Sub
|