' This script was originally published in the Exchange Cookbook, ' (http://www.exchangebookcook.com). Written by Paul Robichaux, ' Missy Koslosky, and Devin Ganger. Redistributed with permission ' of the publisher, O'Reilly & Associates. ' This code adds a mailbox in the first MDB on the server to an ' existing user object ' ------ SCRIPT CONFIGURATION ------ strDCName = "" ' e.g. "batman" strUserName = "CN=" ' e.g. "Random User" ' ------ END CONFIGURATION ------ ' get the default and config NC names Set oIADS = GetObject("LDAP://RootDSE") strDefaultNC = oIADS.Get("defaultnamingcontext") strConfigNC = oIADS.Get("configurationNamingContext") 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.Connection") set oCommand = CreateObject("ADODB.Command") Set oRecordSet = CreateObject("ADODB.Recordset") oConnection.Provider = "ADsDSOObject" oConnection.Open "ADs Provider" ' Build the query to find the private MDBs. Use the first one if any are found. strQuery = ";(objectCategory=msExchPrivateMDB);name,adspath;subtree" oCommand.ActiveConnection = oConnection oCommand.CommandText = strQuery Set oRecordSet = oCommand.Execute If Not oRecordSet.EOF Then oRecordSet.MoveFirst firstMDB = CStr(oRecordSet.Fields("ADsPath").Value) Else firstMDB = "" End If ' create the mailbox oMailbox.CreateMailbox firstMDB oIADSUser.SetInfo WScript.Echo "Created mailbox for " & strUserName