Hello All:
Our client just sent us a huge list of users in an Excel spreadsheet that they want us to add to an Active Directory so they can view a website that we have created for them using SharePoint portal. I was looking for a script and thanks to some of you guys here on this forum, I found one which I modified a little bit to work. I tested this script with a small numbers of users (around 50) in a spreadsheet and it adds all of them to the AD. But when I tried to use the original spreadsheet that has thousands of records, it fails and gives me an error after only inserting 100 records into the AD. And the erorr that I get is all the time different but mostly the content of the error is as follows with the line number different.
"A device attached to the system is not function. Code: 8007001f Source: (null)"
The line number where the error allegedly occurs is always different.
Can someone help.
thanks.
code below.
'Parent container of new user
Dim oContainer
'created user
Dim oUser
'Set the file type and location where we are going to get the data from
set x = getobject(,"excel.application")
Set objWorkbook = x.Workbooks.Open("D:\Users\new_active_dir.xls")
'Start from the second row of the spreadsheet
r = 2
Const ou_name = "Allusers"
do until len(x.cells(r, 1).value) = 0
first_name = x.cells(r, 1).value
last_name = x.cells(r, 2).value
title = x.cells(r, 3).value
phone = x.cells(r, 6).value
login = x.cells(r, 7).value
email = x.cells(r, 7).value
dmisId = x.cells(r, 10).value
dmisName = x.cells(r, 12).value
firstName = replace(first_name, " ","")
pswString = LCase(firstName)
pswdtxt = "!BLA" & pswString & "4me"
'Set the path to the appropriate network.
set oContainer = GetObject("LDAP://OU=NEW_Users,OU=Allusers,DC=company,DC=com")
'Add users data
fullName = first_name & " " & last_name
Set oUser = oContainer.Create("User","CN=" & fullName)
oUser.Put "samAccountName", LCase(firstName) & "." & LCase(last_name)
oUser.SetInfo
oUser.Put "userPrincipalName", email
oUser.SetInfo
oUser.Put "displayName", fullName
oUser.SetInfo
oUser.Put "givenName", first_name
oUser.SetInfo
oUser.Put "mail", email
oUser.SetInfo
oUser.Put "sn", last_name
oUser.SetInfo
oUser.Put "telephoneNumber", phone
oUser.SetInfo
oUser.Put "physicalDeliveryOfficeName", dmisId & " - " & dmisName
oUser.SetInfo
oUser.PUt "description", "New User"
oUser.SetInfo
oUser.SetPassword pswdtxt
oUser.SetInfo
oUser.AccountDisabled = False
oUser.SetInfo
'If there is an error then show error otherwise display confirmation texts in the assigned cells
If Err.Number <> 0 And Err.Number <> -2147019886 Then
x.cells(r, 17).value = err.number & ": " & "ID creation error"
Else
x.cells(r, 14).value = "created"
x.cells(r, 15).value = pswdtxt
x.cells(r, 16).value = LCase(firstName) & "." & LCase(last_name)
end if
r = r + 1
set objOU = Nothing
set oUser = Nothing
set o = nothing
Err.Clear
'Add the users to a particular group
set grp = GetObject("LDAP://CN=NewUsersGroup,OU=UserGroups,OU=AllUsers,DC=company,DC=com")
grp.Add("LDAP://CN="&fullName&",OU=NEW_Users,OU=AllUsers,DC=company,DC=com")
grp.SetInfo
Set grp=Nothing
Loop
set x = nothing
msgbox "Successfully added to Active Directory"
"Behind every great fortune there lies a great crime", Honore De Balzac
Our client just sent us a huge list of users in an Excel spreadsheet that they want us to add to an Active Directory so they can view a website that we have created for them using SharePoint portal. I was looking for a script and thanks to some of you guys here on this forum, I found one which I modified a little bit to work. I tested this script with a small numbers of users (around 50) in a spreadsheet and it adds all of them to the AD. But when I tried to use the original spreadsheet that has thousands of records, it fails and gives me an error after only inserting 100 records into the AD. And the erorr that I get is all the time different but mostly the content of the error is as follows with the line number different.
"A device attached to the system is not function. Code: 8007001f Source: (null)"
The line number where the error allegedly occurs is always different.
Can someone help.
thanks.
code below.
'Parent container of new user
Dim oContainer
'created user
Dim oUser
'Set the file type and location where we are going to get the data from
set x = getobject(,"excel.application")
Set objWorkbook = x.Workbooks.Open("D:\Users\new_active_dir.xls")
'Start from the second row of the spreadsheet
r = 2
Const ou_name = "Allusers"
do until len(x.cells(r, 1).value) = 0
first_name = x.cells(r, 1).value
last_name = x.cells(r, 2).value
title = x.cells(r, 3).value
phone = x.cells(r, 6).value
login = x.cells(r, 7).value
email = x.cells(r, 7).value
dmisId = x.cells(r, 10).value
dmisName = x.cells(r, 12).value
firstName = replace(first_name, " ","")
pswString = LCase(firstName)
pswdtxt = "!BLA" & pswString & "4me"
'Set the path to the appropriate network.
set oContainer = GetObject("LDAP://OU=NEW_Users,OU=Allusers,DC=company,DC=com")
'Add users data
fullName = first_name & " " & last_name
Set oUser = oContainer.Create("User","CN=" & fullName)
oUser.Put "samAccountName", LCase(firstName) & "." & LCase(last_name)
oUser.SetInfo
oUser.Put "userPrincipalName", email
oUser.SetInfo
oUser.Put "displayName", fullName
oUser.SetInfo
oUser.Put "givenName", first_name
oUser.SetInfo
oUser.Put "mail", email
oUser.SetInfo
oUser.Put "sn", last_name
oUser.SetInfo
oUser.Put "telephoneNumber", phone
oUser.SetInfo
oUser.Put "physicalDeliveryOfficeName", dmisId & " - " & dmisName
oUser.SetInfo
oUser.PUt "description", "New User"
oUser.SetInfo
oUser.SetPassword pswdtxt
oUser.SetInfo
oUser.AccountDisabled = False
oUser.SetInfo
'If there is an error then show error otherwise display confirmation texts in the assigned cells
If Err.Number <> 0 And Err.Number <> -2147019886 Then
x.cells(r, 17).value = err.number & ": " & "ID creation error"
Else
x.cells(r, 14).value = "created"
x.cells(r, 15).value = pswdtxt
x.cells(r, 16).value = LCase(firstName) & "." & LCase(last_name)
end if
r = r + 1
set objOU = Nothing
set oUser = Nothing
set o = nothing
Err.Clear
'Add the users to a particular group
set grp = GetObject("LDAP://CN=NewUsersGroup,OU=UserGroups,OU=AllUsers,DC=company,DC=com")
grp.Add("LDAP://CN="&fullName&",OU=NEW_Users,OU=AllUsers,DC=company,DC=com")
grp.SetInfo
Set grp=Nothing
Loop
set x = nothing
msgbox "Successfully added to Active Directory"
"Behind every great fortune there lies a great crime", Honore De Balzac