p***@gmail.com
2014-05-02 16:37:11 UTC
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:\MScripts\JustGroupListadmin.txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile2 = objFSO.OpenTextFile(GrpWrite)
Set objFile = objFSO.CreateTextFile("C:\MScripts\Members1.txt")
Set objFile4 = objFSO.OpenTextFile("C:\MScripts\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"
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:\MScripts\JustGroupListadmin.txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile2 = objFSO.OpenTextFile(GrpWrite)
Set objFile = objFSO.CreateTextFile("C:\MScripts\Members1.txt")
Set objFile4 = objFSO.OpenTextFile("C:\MScripts\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"