Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with creating users using vbScript

Status
Not open for further replies.

windowsfan

IS-IT--Management
Jan 26, 2007
237
US
I have the belw script which reads excel worksheet to create users. It's working fine. Only thing I cannot make work is cannot add users to groups and cannot set expiration data on account (by date or never). Can I please get some help?

objUser.accountExpires=strAcctExp (value in excel I want to use is date (1/1/2009) or never.

objUser.memberOf=strMemberOf
(value in excel is:
CN=PACS Residents,OU=Clinician,OU=PACS,OU=BH Application Groups,DC=zhc,DC=botsford,DC=org;CN=PACS Fellows,OU=Clinician,OU=PACS,OU=BH Application Groups,DC=zhc,DC=botsford,DC=org;

Here's the full script:


Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet
Dim strCN, strSam, strFirst, strLast, strMI, strPWD, strDept, strDesc, strDispName,strTN,strPager
Dim strMail, strUPN, strOffice, strAcctExp,strTitle, strHomeDrive,strHomeDirectory,strMemberOf
Dim strmsExchHomeServerName, strmailnickname,strmDBUseDefaults,strhomeMDB


strOU = "OU=NewUsers," ' Note the comma
strSheet = "C:\NewUser1.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


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)
strTN = Trim(objExcel.Cells(intRow, 8).Value)
strDept = Trim(objExcel.Cells(intRow, 9).Value)
strTitle= Trim(objExcel.Cells(intRow,10).Value)
strUPN=Trim(objExcel.Cells(intRow, 11).Value)
strMail=Trim(objExcel.Cells(intRow, 12).Value)
strOffice= Trim(objExcel.Cells(intRow, 13).Value)
strAcctExp= Trim(objExcel.Cells(intRow,14).Value)
strPWD = Trim(objExcel.Cells(intRow, 15).Value)
strHomeDrive = Trim(objExcel.Cells(intRow, 16).Value)
strHomeDirectory = Trim(objExcel.Cells(intRow, 17).Value)
strMemberOf=Trim(objExcel.Cells(intRow, 18).Value)
strmailnickname=Trim(objExcel.Cells(intRow, 19).Value)
strhomeMDB=Trim(objExcel.Cells(intRow, 20).Value)
strmsExchHomeServerName=Trim(objExcel.Cells(intRow, 21).Value)
strmDBUseDefaults=Trim(objExcel.Cells(intRow, 22).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.telephoneNumber=strTN
objUser.description=strDesc
objUser.department=strDept
objUser.title=strTitle
objUser.userPrincipalName=strUPN
objUser.mail=strMail
' objUser.accountExpires=strAcctExp
'Set Accounts Expiration Date:
' objUser.AccountExpirationDate = strAcctExp

' objUser.physicalDeliveryOfficeName=strOffice

objUser.homeDrive=strHomeDrive
objUser.homeDirectory=strHomeDirectory
' objUser.memberOf=strMemberOf
objUser.SetInfo

'MailBox
objUser.msExchHomeServerName=strmsExchHomeServerName
objUser.mailnickname=strmailnickname
'objUser.mDBUseDefaults=strmDBUseDefaults
objUser.homeMDB=strhomeMDB

' Separate section to enable account with its password

objUser.userAccountControl = 512
objUser.pwdLastSet = 0
objUser.SetPassword strPWD
objUser.SetInfo


intRow = intRow + 1
Loop
objExcel.Quit
WScript.Echo "Successfully created Users"




WScript.Quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top