add e-mail column to this script

Hello,

I have found a scipt to export members from a distributiongroup and this work fine, but i also want the e-mail address exported true this script, so just an extra column.

can someone help me because i don't know where to start?

THe script


'Script begins here
Dim objGroup, objUser, objFSO, objFile, strDomain, strGroup, Domain, Group
 
'Change DomainName to the name of the domain the group is in
strDomain = Inputbox ("Enter the Domain name", "Data needed", "domainname")
 
'Change GroupName to the name of the group whose members you want to export
strGroup = InputBox ("Enter the Group name", "Data needed", "groupname")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
'On the next line change the name and path of the file that export data will be written to.
Set objFile = objFSO.CreateTextFile("C:\" & strGroup & " - Members.txt")
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
For Each objUser In objGroup.Members
    objFile.WriteLine objUser.Name & " - " & objUser.Class
Next
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Set objUser = Nothing
Set objGroup = Nothing
Wscript.Echo "Done"
Wscript.Echo "Please check the c: for your output file"

Open in new window

juriangAsked:
Who is Participating?
 
David LeeConnect With a Mentor Commented:
Hi, juriang.

Try this version.
'Script begins here
Dim adoRS, arrMembers, varMember, objFSO, objFile, strDomain, strGroup, objUser
 
'Change DomainName to the name of the domain the group is in
strDomain = Inputbox ("Enter the Domain name", "Data needed", "domainname")
 
'Change GroupName to the name of the group whose members you want to export
strGroup = InputBox ("Enter the Group name", "Data needed", "groupname")
 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
'On the next line change the name and path of the file that export data will be written to.
Set objFile = objFSO.CreateTextFile("C:\" & strGroup & " - Members.txt")
 
Set adoRS = Wscript.CreateObject("ADODB.Recordset")
adoRS.ActiveConnection = "Provider=ADSDSOObject"
adoRS.Source = "SELECT adsPath,member FROM 'LDAP://" & strDomain & "' WHERE objectClass='group' AND Name='" & strGroup & "'"
adoRS.CursorType = 0
adoRS.CursorLocation = 2
adoRS.LockType = 1
adoRS.Open()
While Not adoRS.EOF
	With adoRS
	    arrMembers = .Fields("Member")
	    For Each varMember In arrMembers
			Set objUser = GetObject("LDAP://" & varMember)
			objFile.WriteLine objUser.displayName & " - " & objUser.class & " - " & objUser.mail
		Next
    	adoRS.MoveNext
    End With
Wend
adoRS.Close
Set adoRS = Nothing
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Wscript.Echo "Done"
Wscript.Echo "Please check the c: for your output file"
WScript.Quit

Open in new window

0
 
Pratima PharandeConnect With a Mentor Commented:
you mean to say you just need one extra column in Extracted text file
and Extra filed(email) is in objGroup

change the Email with proper filedname like class and name
try this

you need to change only in this

    objFile.WriteLine objUser.Name & " - " & objUser.Class & " - " & objUser.Email
For Each objUser In objGroup.Members
    objFile.WriteLine objUser.Name & " - " & objUser.Class & " - " & objUser.Email
Next

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.