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

Help adding users to group from text file

Status
Not open for further replies.

gmagerr

Technical User
Aug 11, 2001
323
US
Hi all
I need to create a security group with all of the members of a distribution group. The distribution group is populated nightly by a program called SmartDL. I am able to grab all of the users from the distribution group and save them to a text file. When i try to add the users from the text file to my security group, i get an error saying "error: Object Required" then lists the users name. It errors after the first user. Can anyone help? Thanks.

Code:
'==========================================================================
' 
' NAME: Populate IST Project Group.vbs
' 
' AUTHOR: Gene Magerr		
' EMAIL: genemagerr@hotmail.com
'
' COMMENT:
'
'==========================================================================
Option Explicit

'==========================================================================
' VARIABLE DECLARATIONS
'==========================================================================
Dim objFSO, arrMemberOf, objGroup, objFileNew, objFile, objUserS 
Dim objGroupNew, arrUserList, strNewUser, TestMode, strMember

Set objFSO = CreateObject("Scripting.FilesystemObject")

'==========================================================================
' STATIC VARIABLE ASSIGNMENTS
'==========================================================================
Const FOR_READING = 1, FOR_WRITING = 2, FOR_APPENDING = 8

'==========================================================================
' MAIN SCRIPT CODE
'==========================================================================

Set objGroup = GetObject("LDAP://cn=All IST Members,ou=groups,dc=company,dc=com")
objGroup.GetInfo
 
arrMemberOf = objGroup.GetEx("member")

If Not objFSO.FileExists("c:\ist_new.txt") Then
objFSO.CreateTextFile("c:\ist_new.txt")
End If

Set objFileNew = objFSO.OpenTextFile("c:\ist_new.txt",2, True)

For Each strMember in arrMemberOf
Set objUserS = GetObject("LDAP://" & strMember)
objUserS.GetInfo
objFileNew.WriteLine(objUserS.Get("displayName"))
Next


objFileNew.Close
Set objFile = objFSO.OpenTextFile("c:\ist_new.txt",1)


Set objGroupNew = GetObject("LDAP://cn=_genetest,ou=groups,dc=company,dc=com")

Do Until objFile.AtEndOfStream
    strNewUser = objFile.Readline
    arrUserList = Split(strNewUser , vbCrLf)
    
    For Each strNewUser In arrUserList
    WScript.Echo strNewUser
    
    objGroupNew.add strNewUser.adspath
    
    Next
Loop
 
The culprit is here:
strNewUser.adspath
A string read from a file can't be an object ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[1] Would be better off by simply saving the dn.
[tt]
For Each strMember in arrMemberOf
[red]'[/red]Set objUserS = GetObject("LDAP://" & strMember)
[red]'[/red]objUserS.GetInfo
[red]'[/red]objFileNew.WriteLine(objUserS.Get("displayName"))
[blue]objFileNew.WriteLine strMember[/blue]
Next
[/tt]
[2] With that the 2nd functionality would be much simpler as well.
[tt]
Do Until objFile.AtEndOfStream
strNewUser = objFile.Readline
[red]'[/red]arrUserList = Split(strNewUser , vbCrLf)

[red]'[/red]For Each strNewUser In arrUserList
WScript.Echo strNewUser

[red]'[/red]objGroupNew.add strNewUser.adspath
[blue]objGroupNew.add "LDAP://" & strNewUser[/blue]

Next
Loop
[/tt]
[3] If displayName is that important to be persistently stored in a file, you can manage it to save it independently. It is of course not impossible to obtain adspath from displayName, but it is more expensive. Also save the strMemeber directly has already saved you those extra binding to user object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top