' 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 will read the contents of an Excel file and use the fields
' to create a set of mailboxes
' ------ SCRIPT CONFIGURATION ------
strExchangeServerName = "<serverName>" ' e.g. " batman"
strWorksheetName = "<filePath>" ' e.g. "c:\data\excelSheet.xls"; replace with actual name
strTargetMDB = "<someMDB>"
strTargetContainer = "cn=users,<forestDN>" ' e.g. "cn=Users, dc=domain, dc=com"
' ------ END CONFIGURATION ---------
' create an invisible Excel instance and open our specified workbook
set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(strWorksheetName)
' assume that row 1 is header data, and that rows 2-N contain data
' Columns:
' 1: first name
' 2: last name
' 3: CN
' 4: alias
currentRow = 2
Do until objExcel.Cells(currentRow, 1).Value =""
userFirst = objExcel.Cells(currentRow, 1).Value
userLast = objExcel.Cells(currentRow, 2).Value
userCN = objExcel.Cells(currentRow, 3).Value
userAlias = objExcel.Cells(currentRow, 4).Value
Set objTargetContainer = GetObject(strTargetContainer)
Set objUser = objOU.objTargetContainer _
("User", "cn=" & userCN)
objUser.sAMAccountName = userAlias
objUser.GivenName = userFirst
objUser.SN = userLast
objUser.AccountDisabled = FALSE
objUser.SetInfo
objUser.CreateMailbox targetMDB
currentRow = currentRow + 1
Loop
objExcel.quit
WScript.Echo "Imported " & currentRow -1 & " objects"
|