I am total newbie when it comes to VBScript, but I've been piecing some things together little by little. Anyway, what I'd like to do is create a VBScript that utilizes an Excel document, and adds a batch of users to a specific Active Directory OU.
I've been able to do 90% of it, but now I'm stuck with some minor details. I'm attaching my code below in hopes that someone can point me in the right direction.
What I'd like the script to do is: 1.) assign the users to a specific group(s) 2.) Set it so that their password never expires and 3.) Set it so that they cannot change their passwords. Also, if you can spot any redundancy or anything else I've done wrong, that would be great too! Thanks in advance!
Here's my code, hopefully it's an easy tweak:
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet
Dim strCN, strUPN, strFirst, strLast, strPWD, strDescription
strOU = "OU=Accounting ,"
strSheet = "D:\scripts\import.xls"
' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 3
' 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 = ""
strUPN = Trim(objExcel.Cells(intRow, 1).Value)
strCN = Trim(objExcel.Cells(intRow, 2).Value)
strFirst = Trim(objExcel.Cells(intRow, 3).Value)
strLast = Trim(objExcel.Cells(intRow, 4).Value)
strPWD = Trim(objExcel.Cells(intRow, 5).Value)
strDescription = Trim(objExcel.Cells(intRow, 6).value)
strOU = Trim(objExcel.Cells(intRow, 7).value)
' Build the actual User from data in strSheet.
Set objUser = objContainer.Create("User", "cn=" & strCN)
objUser.userPrincipalName = strUPN
objUser.givenName = strFirst
objUser.sn = strLast
objuser.description = strDescription
' Separate section to enable account with its password
objUser.userAccountControl = 512
objUser.pwdLastSet = 0
intRow = intRow + 1
' End of Sample UserSpreadsheet VBScript.