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

Need help with multiple loops 1

Status
Not open for further replies.

wscriscillis

IS-IT--Management
May 2, 2014
2
US
Can you take a look at this VBScript and help me figure out what I’m doing wrong.

It reads in two files, One has four users and the other has 45 group Names

It reads the users in first, then translates their NT name to a DN Name in an endofstream loop

Inside of that loop it starts another endofstream loop with the group names and adds the users to each group.

The issue that I’m having is it is only adding the first name listed in the username file. It IS adding that one user to ALL the group.

I have a writeline within the loop to see if it going through all of the names and it is writing all four names out to the file.

What am I missing here?


'Script begins here
Dim objGroup, objUser, objFSO, objFile, strDomain, strGroup, Domain, Group
'translate settings
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_PROPERTY_APPEND = 3
Dim NameTranslate
Set NameTranslate = CreateObject("NameTranslate")

NameTranslate.Init ADS_NAME_INITTYPE_GC, ""

Dim NT4Name, DN

GrpWrite = ("C:Mscript\JustGroupListadmin.txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile2 = objFSO.OpenTextFile(GrpWrite)
Set objFile = objFSO.CreateTextFile("C:Mscript\Members1.txt")
Set objFile4 = objFSO.OpenTextFile("C:Mscript\GroupInfo.txt")

'Change DomainName to the name of the domain the group is in

strDomain = "JUS"

'Change GroupName to the name of the group whose members you want to export


Do while NOT objFile2.AtEndOfStream

strGroup = objFile2.ReadLine

'translating NT name to DN
NT4Name = strDomain & "\" & strGroup
NameTranslate.Set ADS_NAME_TYPE_NT4, NT4Name
DN = NameTranslate.Get(ADS_NAME_TYPE_1779)

set UsertoAdd = GetObject("LDAP://" & DN)

'Pulling names of groups from txt and adding name translated above

Do while NOT objFile4.AtEndOfStream

AdminGroup = objFile4.ReadLine
Set DestGroup = Getobject("LDAP://CN=" & AdminGroup & ",OU=MOVEit,OU=COTS,OU=Groups,DC=EAS,DC=DS,DC=KY,DC=gov")
DestGroup.add(UsertoAdd.ADsPath)


Loop



objFile.WriteLine UsertoAdd.ADsPath


Loop



objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Set objUser = Nothing
Set objGroup = Nothing
Wscript.Echo "Done"

 
I don't see any vbscript errors, the loops look fine. It's almost like there is an "on error resume next" suppressing runtime errors, but I see you don't have that line (which is good).

I would try adding writeline to the inner loop to see it is being run 45 times for each user.

Also, leading / trailing spaces on the input could mess you up, maybe use strGroup = [highlight #FCE94F]Trim([/highlight]objFile2.ReadLine[highlight #FCE94F])[/highlight] ... (but then, I would expect a runtime error if extra spaces were the problem)

(I will say that I am not familiar with NameTranslate, LDAP etc, so the problem may be with that syntax)
 
...
Do while NOT objFile2.AtEndOfStream
...
Set objFile4 = objFSO.OpenTextFile("C:Mscript\GroupInfo.txt")
Do while NOT objFile4.AtEndOfStream
...
Loop
objFile4.Close
objFile.WriteLine UsertoAdd.ADsPath
Loop
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top