| |
boston18
Posts: 2
Score: 0
Joined: 4/2/2008
Status: offline
|
Hi All, I found and modified this script some to create AD users and with Emails In active Directory. I am needing to modify it some more to add the user created to AD groups, Ideally based upon the description of the user created. Any Ideas or Guidance would be greatly appreciated. Here is what I have thus far Cheers Option Explicit Dim objRootLDAP, objContainer, objUser, objShell,objGroup Dim objExcel, objSpread, intRow 'For Creating account attribute Dim strUser, strOU, strSheet Dim strCN, strSam, strFirst, strLast, strPWD, strsn, strPrincipalName, strDC1, strDC2, strCompany,strDepart Dim strUserAcct, strDisplayName, strDescription, strDNSDomain 'for Exchange Attributes Dim strmail, strmsExchHomeServerName,strMailAddress,strmDBUseDefaults, strmailnickname, strhomeMDB Dim objMailbox, strproxyAddresses, strmemberOf,strGroup strSheet = "C:\New_users.xls" ' Bind to Active Directory, Users container. Set objRootLDAP = GetObject("LDAP://rootDSE") Set objContainer = GetObject("LDAP://" & strOU & _ objRootLDAP.Get("defaultNamingContext")) ' Open the Excel spreadsheet Set objExcel = CreateObject("Excel.Application") Set objSpread = objExcel.Workbooks.Open(strSheet) intRow = 3 'Row 1 often contains headings, Row 2 for showing numbering ' Here is the 'DO...Loop' that cycles through the cells ' Note intRow, x must correspond to the column in strSheet Do Until objExcel.Cells(intRow,1).Value = "" strSam = Trim(objExcel.Cells(intRow, 1).Value) strFirst = Trim(objExcel.Cells(intRow, 2).Value) strLast = Trim(objExcel.Cells(intRow, 3).Value) strDisplayName = Trim(objExcel.Cells(intRow, 4).Value) strCN = Trim(objExcel.Cells(intRow, 5).Value) strCompany = Trim(objExcel.Cells(intRow, 6).Value) strUserAcct = Trim(objExcel.Cells(intRow, 7).Value) strPWD = Trim(objExcel.Cells(intRow, 8).Value) strPrincipalName = Trim(objExcel.Cells(intRow, 9).Value) strDC1 = Trim(objExcel.Cells(intRow, 10).Value) strDC2 = Trim(objExcel.Cells(intRow, 11).Value) strDescription = Trim(objExcel.Cells(intRow, 12).Value) 'Getting info for creating Email account strmsExchHomeServerName = objExcel.Cells(intRow, 13).Value strmail = Trim(objExcel.Cells(intRow, 14).Value) strmailnickname = Trim(objExcel.Cells(intRow, 15).Value) strmDBUseDefaults=Trim(objExcel.Cells(intRow, 16).Value) strhomeMDB = objExcel.Cells(intRow, 17).Value 'strproxyAddresses = objExcel.Cells(intRow, 18).Value Set objContainer = GetObject("LDAP://" & strOU & _ objRootLDAP.Get("defaultNamingContext")) 'Calling Sub routine to read information and create mailbox Call GetInfo() call CreateMailBox() 'Clean up variable to avoid it reput container Set objContainer = Nothing intRow = intRow + 1 Loop ' Build the actual User from data in strSheet by using a Sub Function Sub GetInfo() Set objUser = objContainer.Create("User", "cn=" & strCN) objUser.sAMAccountName = strSam objUser.givenName = strFirst objUser.sn = strLast objUser.userPrincipalName = strPrincipalName objUser.DisplayName = strDisplayName objUser.Description = strDescription objUser.SetInfo ' Separate section to enable account with its password objUser.SetPassword strPWD objUser.Put"userAccountControl", 512 'objUser.pwdLastSet = 0 objUser.SetInfo WScript.Echo(" User Account "& strSam & " has been created") End Sub 'Sub function to create Mailbox Sub CreateMailBox() Set objMailbox = objUser objMailbox.homeMDB = strhomeMDB objMailbox.CreateMailbox strhomeMDB objMailbox.msExchHomeServerName = strmsExchHomeServerName objMailbox.mail = strmail objMailbox.mailnickname = strmailnickname objUser.SetInfo End Sub objExcel.Quit WScript.Quit
_____________________________
chris
|
|