Question : How to write users to a txt file from 2 security groups

I am currently using a vbs script to write users to a text file.  I now need to pull users from 2 groups into the same file but I am unsure how to do this.  The script is below.  The 1st group is Set objGroup = GetObject("LDAP://CN=PaperCut Users,DC=corp,DC=smithbucklin,DC=com") and the one  I would like to add is Set objGroup = GetObject("LDAP://CN=Copier Users,DC=corp,DC=smithbucklin,DC=com")
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("d:\ibb\data\user\data\users.txt", 2)
Set objGroup = GetObject("LDAP://CN=PaperCut Users,DC=corp,DC=smithbucklin,DC=com")
objGroup.GetInfo
 
arrMemberOf = objGroup.GetEx("member")
For Each strMember in arrMemberOf
    Set objuser = GetObject("LDAP:// " & strMember)
     If (len(objuser.GivenName)>1) Then
 
			   
		firstName		= objuser.GivenName       
		lastName		= objuser.SN
		networkLogin		= objuser.SamAccountName
		ibbLogin		= objuser.telephoneNumber
		jobTitle		= objuser.title
		siteCode		= objuser.physicalDeliveryOfficeName
		email			= objuser.mail
		location		= objuser.l
 
           
       		f.Write firstName & "|" & lastName & "|" & networkLogin & "|" & ibbLogin & "|" & jobTitle & "|" & siteCode & "|" & email & "|" & location & "|" & strMember
       		f.WriteBlankLines (1)
     end if
Next

Answer : How to write users to a txt file from 2 security groups

Hi there, this should work.  I've just used an array to loop through the groups, writing the group name, and its members as it goes through.

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateTextFile("d:\ibb\data\user\data\users.txt", True)
arrGroups = Array( _
	"LDAP://CN=PaperCut Users,DC=corp,DC=smithbucklin,DC=com", _
	"LDAP://CN=Copier Users,DC=corp,DC=smithbucklin,DC=com" _
	)
For Each strGroupPath In arrGroups
	Set objGroup = GetObject(strGroupPath)
	objGroup.GetInfo
	
	arrMemberOf = objGroup.GetEx("member")
	f.WriteLine "GROUP MEMBERS OF: " & objGroup.CN
	For Each strMember in arrMemberOf
		Set objuser = GetObject("LDAP:// " & strMember)
		If (len(objuser.GivenName)>1) Then	 
			firstName		= objuser.GivenName       
			lastName		= objuser.SN
			networkLogin	= objuser.SamAccountName
			ibbLogin		= objuser.telephoneNumber
			jobTitle		= objuser.title
			siteCode		= objuser.physicalDeliveryOfficeName
			email			= objuser.mail
			location		= objuser.l
			
			f.Write firstName & "|" & lastName & "|" & networkLogin & "|" & ibbLogin & "|" & jobTitle & "|" & siteCode & "|" & email & "|" & location & "|" & strMember
			f.WriteBlankLines (1)
		End If
	Next
	f.WriteBlankLines(1)
Next
f.Close
MsgBox "Finished."
Random Solutions  
 
programming4us programming4us