Hi Mark,
Every thing is working fine as except,
1)I am not able to read AccountExpirationDate from worksheet. It gives me mismatch error.
2)Is it something I can configure in the script for Password so they dont have to change it firs time they login.
3)After the script is ran, I can only open the worksheet I used in readonly mode. How can I fix this?
Option Explicit
Dim objRootLDAP,objContainer,objUser,objShell,FileServer
Dim objExcel, objSpread, intRow,FSO
Dim strUser, strOU, strSheet
Dim strCN, strSam, strFirst, strLast, strMI, strPWD, strDept, strDesc, strDispName
Dim strUPN,strAcctExp,strTitle, strHomeDrive,strHomeDirectory
Dim cellarray,entry, objGroup
Const ADS_PROPERTY_APPEND = 3
strOU = "OU=NewUsers," 'Note the comma
strSheet = "C:\Externs1.xls"
Set fso = CreateObject("Scripting.FileSystemObject")
' 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)
'Set FileServer = fso.GetFolder(\\ntuser\user)
intRow = 3 'Row 1 often contains headings
' 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)
strCN = Trim(objExcel.Cells(intRow, 2).Value)
strFirst = Trim(objExcel.Cells(intRow, 3).Value)
strLast = Trim(objExcel.Cells(intRow, 4).Value)
strMI=Trim(objExcel.Cells(intRow, 5).Value)
strDispName=Trim(objExcel.Cells(intRow, 6).Value)
strDesc = Trim(objExcel.Cells(intRow, 7).Value)
strDept = Trim(objExcel.Cells(intRow, 8).Value)
strTitle= Trim(objExcel.Cells(intRow,9).Value)
strUPN=Trim(objExcel.Cells(intRow, 10).Value)
strPWD = Trim(objExcel.Cells(intRow, 11).Value)
strHomeDrive = Trim(objExcel.Cells(intRow, 12).Value)
strHomeDirectory = Trim(objExcel.Cells(intRow,13).Value)
strAcctExp= Trim(objExcel.Cells(intRow,14).Value)
' Build the actual User from data in strSheet.
Set objUser = objContainer.Create("User", "cn=" & strCN)
objUser.sAMAccountName = strSam
objUser.givenName = strFirst
objUser.sn = strLast
objUser.initials=strMI
objUser.displayName=strDispName
objUser.description=strDesc
objUser.department=strDept
objUser.title=strTitle
objUser.userPrincipalName=strUPN
objUser.homeDrive=strHomeDrive
objUser.homeDirectory=strHomeDirectory
objUser.SetInfo
'Adds user to BH Residents Group
Set objGroup = GetObject("LDAP://CN=BH Externs,OU=Existing Groups,OU=BH Application Groups,DC=zhc,DC=botsford,DC=org")
objGroup.PutEx ADS_PROPERTY_APPEND,"member", Array("CN=" & strCN &",ou=NewUsers,dc=zhc,dc=botsford,dc=org")
objGroup.SetInfo
' Separate section to enable account with its password
objUser.userAccountControl = 512
objUser.pwdLastSet = 0
objUser.SetPassword strPWD
objUser.SetInfo
'Account Expiration
Set objUser = GetObject("LDAP://CN=" & strCN &",ou=NewUsers,dc=zhc,dc=botsford,dc=org")
objUser.AccountExpirationDate=strAcctExp
objUser.SetInfo
intRow = intRow + 1
Loop
'objExcel.Quit
objExcel.Application.Quit
WScript.Echo "Successfully created Users"
set objGroup=nothing
set objExcel=nothing
set objUser=nothing
set objRootLDAP=nothing
set objContainer=nothing
set objUser=nothing
set objShell=nothing
set objSpread=nothing
set intRow=nothing