I have a beta script I am wanting to recurse through all domain users (domain = mydomain.com), creating a mailbox for each. Can you help me with the script I have, thus far?
' ------ SCRIPT CONFIGURATION ------
strDCName = "DCone"
strUserName = "CN=<userCN>" '???NEED to recurse this value, looking at entries in an external CSV file, column one
' ------ END CONFIGURATION ------
' get the default and config NC names
Set oIADS = GetObject("LDAP://RootDSE"
)
strDefaultNC = oIADS.Get("defaultnamingco
ntext")
strConfigNC = oIADS.Get("configurationNa
mingContex
t")
strContainer= "/CN=Users," & strDefaultNC
Set objContainer = GetObject("LDAP://" & strDCName & strContainer)
' find the target user
Set oIADSUser = GetObject("LDAP://" & strUserName & ",CN=Users," & strDefaultNC)
Set oMailBox = oIADSUser
' Open the Connection.
Set oConnection = CreateObject("ADODB.Connec
tion")
set oCommand = CreateObject("ADODB.Comman
d")
Set oRecordSet = CreateObject("ADODB.Record
set")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "ADs Provider"
' Build the query to find the private MDBs. Use the first one if any are found.
strQuery = "<LDAP://" & strConfigNC & _
">;(objectCategory=msExchP
rivateMDB)
;name,adsp
ath;subtre
e"
oCommand.ActiveConnection = oConnection
oCommand.CommandText = strQuery
Set oRecordSet = oCommand.Execute
If Not oRecordSet.EOF Then
oRecordSet.MoveFirst
firstMDB = CStr(oRecordSet.Fields("AD
sPath").Va
lue)
Else
firstMDB = ""
End If
' create the mailbox
oMailbox.CreateMailbox firstMDB
oIADSUser.SetInfo
WScript.Echo "Created mailbox for " & strUserName
Start Free Trial