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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding users to groups

Status
Not open for further replies.

rlee80

MIS
May 20, 2004
10
GB
Hi

I have an excel file containing User information from my windows 2000 domain.
File is in the format of column A contains common name eg. Bloggs Joe
Column E contains OU name and
Column F contains Group name.

I have other info in other columns like first name last name, SAM Account name etc.

Using the script below I get an error number but no description error number is 2147463168

What am I doing wrong?

Thanks in advance for any help.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("D:\newusers.xls")

On Error Resume Next

intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""

strGroup = "cn=" & objExcel.Cells(intRow, 6).Value & ",ou=groups,dc=testing,dc=com"
strMember = "cn=" & objExcel.Cells(intRow, 1).Value & "ou=" & objExcel.Cells(intRow, 5).Value & ",dc=testing,dc=com"
Set objGroup = GetObject("LDAP://" & strGroup)
Err.Clear
objGroup.Add("LDAP://" & strMember)
If Err.Number <> 0 Then
Wscript.Echo Err.Number & "--" & Err.Description
Err.Clear
End If
objGroup.SetInfo
intRow = intRow + 1
Loop

 
on what line do you get the error??
take 'on error resume next' out to get a clearer understanding of the issue
 
Thanks for the reply I think the error is from this line

Err.Clear
objGroup.Add("LDAP://" & strMember)
If Err.Number <> 0 Then
Wscript.Echo Err.Number & "--" & Err.Description
Err.Clear
End If

Why do I take on error resume next out, and please excuse my ignorance
 
I see a couple of problems, but I'll show you how I do mine:

Code:
Sub AddMembersToGroup(pMembers, newGroup)
	theMembers = Array()
	ReDim theMembers(pMembers.Count - 1)

	Dim idx:idx = 0
	
	For Each idxMember in pMembers
		theMembers(idx) = pMembers.Item(idxMember)
		idx = idx + 1
	Next
	
	newGroup.PutEx ADS_PROPERTY_APPEND, "Member", theMembers
	newGroup.SetInfo
End Sub

the newGroup variable was obtained like this:

Code:
	Set newGroup = GetObject("LDAP://cn=" & Projectnumber & ",cn=Users,dc=nomadics,dc=com")

and the projMembers was an dictionary object of distinguished names.

I had to have the loop because the PutEx expects an array, not a dictionary object.


 
you should try and get out of the habit of using on error resume next. really you should be using defensive programming techniques to make sure your code doesnt execute something which causes an error.

on error resume next should only be used when you cant predict that an error will or will not exist.

thats not the best description of how and when to use on error resume next but there you go.

i would only suggest using on error resume next just before you deploy your script, as a fail safe so you dont annoy a user etc with some 'funny' error
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top