octavian10
MIS
Hello all,
I have the following script which gets User info from an Excel spreadsheet and creates the users in Active Directory.
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ("D:\Scripts\New_Users.xls")
intRow = 2
Do Until objExcel.Cells (intRow,1).Value = ""
Set objOU = GetObject("LDAP://172.16.5.9/CN=Users, DC=redshift, DC=com")
Set objUser = objOU.Create ("User", "cn=" & objExcel.Cells (intRow, 1).Value)
objUser.SamAccountName = objExcel.Cells (intRow, 2).Value
objUser.GivenName = objExcel.Cells (intRow, 3).Value
objUser.SN = objExcel.Cells (intRow, 4).Value
objUser.SetInfo
intRow = intRow + 1
Loop
objExcel.quit
This works great, but if I run it twice the second time I get a Already Exists error. Which is undestandable. How can I modify the code to update active directory with new users added to this spread sheet so I do not get this error. I am new to scripting and am just doing this to learn but I can see scenerios where somthing like this might come in handy. Hopefully someone can help.
Have a good day.
"I hear and I forget. I see and I remember. I do and I understand."
- Confucius (551 BC - 479)
I have the following script which gets User info from an Excel spreadsheet and creates the users in Active Directory.
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ("D:\Scripts\New_Users.xls")
intRow = 2
Do Until objExcel.Cells (intRow,1).Value = ""
Set objOU = GetObject("LDAP://172.16.5.9/CN=Users, DC=redshift, DC=com")
Set objUser = objOU.Create ("User", "cn=" & objExcel.Cells (intRow, 1).Value)
objUser.SamAccountName = objExcel.Cells (intRow, 2).Value
objUser.GivenName = objExcel.Cells (intRow, 3).Value
objUser.SN = objExcel.Cells (intRow, 4).Value
objUser.SetInfo
intRow = intRow + 1
Loop
objExcel.quit
This works great, but if I run it twice the second time I get a Already Exists error. Which is undestandable. How can I modify the code to update active directory with new users added to this spread sheet so I do not get this error. I am new to scripting and am just doing this to learn but I can see scenerios where somthing like this might come in handy. Hopefully someone can help.
Have a good day.
"I hear and I forget. I see and I remember. I do and I understand."
- Confucius (551 BC - 479)