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 adding IF

Status
Not open for further replies.

SRotblat

Technical User
Sep 6, 2003
52
US
I've got the following script that creates user accounts based on the input of CN/SANAccountName from a XLS file. The file works assuming that the accounts don't exist in the OU specified.

Can someone assist altering so that if the account exists it just resets the password?

SCRIPT:

dim sAMAccountName

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
("C:\xxxx.xls")

intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""
Set objOU = GetObject("LDAP://__location__")
Set objUser = objOU.Create _
("User", "cn=" & objExcel.Cells(intRow, 1).Value)
sAMAccountName = objExcel.Cells(intRow, 2).Value
objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
strNewUPN = sAMAccountName & "@" & "xxx.xxx"
objUser.userPrincipalName = strNewUPN
objUser.SetInfo
objUser.AccountDisabled = FALSE
objUser.SetInfo
objUser.SetPassword("[insertpassword")
ObjUser.SetInfo
intRow = intRow + 1
Loop

objExcel.Quit
 
Do a check first by using GetObject. If that returns without an error, then you can reset the password, otherwise create the object. You will want to use On Error Resume Next at the top of your script so you can capture the error code.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top