Combine the two scripts or run them separately:
'This code pulls user names to create from an Access database:
Dim CNobj0
Set CNobj0 = CreateObject("ADODB.Connection")
Dim RSobj0
Set RSobj0 = CreateObject ("ADODB.Recordset")
CNobj0.Open "DSN=CreateMB;"
RSobj0.Open "SELECT * FROM Create", CNobj0, 1, 1
If not RSobj0.RecordCount = 0 then
Do while Not RSobj0.EOF
'msgbox "Creating " & RSobj0.Fields(0).Value
CreateMailboxCDOPerson RSobj0.Fields(0).Value
wScript.Echo (RSobj0.Fields(0).Value)
RSobj0.MoveNext
Loop
Else
wScript.Echo "No Data"
End If
Set CNobj0 = Nothing
Set RSobj0 = Nothing
Sub CreateMailboxCDOPerson(strMBName)
Dim MyMDBUrl
MyMDBUrl = "LDAP://MyExchangeServer/CN=Mailbox Store," & _
"CN=MyStorageGroupName,CN=InformationStore,CN=MyExchangeServer,CN=Servers,"
& _
"CN=First Administrative Group,CN=Administrative Groups," & _
"CN=Data Life Associates,CN=Microsoft Exchange,CN=Services," & _
"CN=Configuration,DC=mydomain,DC=com"
Dim MyUserURL
MyUserURL = "LDAP://myLDAPserver.mydomain.com/CN=" & strMBName &
",OU=myOU,DC=mydomain,DC=com"
Dim oPerson
Set oPerson = CreateObject("CDO.Person")
oPerson.DataSource.SaveTo MyUserURL
' Create a mailbox.
Dim oMailbox
Set oMailbox = oPerson.GetInterface("IMailboxStore")
oMailbox.CreateMailbox MyMDBUrl
' Save
oPerson.DataSource.Save
' Clean up.
Set oPerson = Nothing
Set oMailbox = Nothing
End Sub
'This code changes the password for the specified account, enables the
'account and sets the password flag to not expire (you can of course make it
'look through records in a DB):
Option Explicit
On Error Resume Next
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Dim objRootDSE
Set objRootDSE = GetObject("LDAP://RootDSE")
Dim iFlag
Dim iNewFlag
Dim objUser
Dim sUserDN
iUser = "username"
sUserDN = "CN=" & iUser & ",OU=myOU.net,DC=mydomain,DC=com"
Set objUser = GetObject("LDAP://" & sUserDN)
objUser.SetPassword "passwordgoeshere"
objUser.AccountDisabled = False
objUser.Put "pwdLastSet", -1
iFlag = objUser.Get("userAccountControl")
iNewFlag = iFlag Or ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userAccountControl", iNewFlag
objUser.SetInfo
If Err.Number = 0 Then
WScript.Echo "Changed PW for user " & iUser
Else
WScript.Echo "ERROR! Could not change PW for user " & iUser
End If
Set objUser = Nothing
Set objRootDSE = Nothing
Microsoft link if you need more functionality:
http://msdn.microsoft.com/library/d..._cdo_creating_a_mailbox_enabled_recipient.asp