Help with a VBScript

I have this VBScript that lists out users and a security group in AD.  Im trying to add their title to the script and i seem to be missing something.  Can someone help?

Option Explicit
Dim Group
Dim GroupName
Dim GroupDomain
Dim Member
Dim title
Dim w
Dim ws
Dim i
Dim Con
Dim Com
Dim RootDSE
Dim sPath
Dim oDepartment
Dim sDepartment

const ForReading = 1
const ForWriting = 2
const ForAppending = 8
Const TristateFalse = 0

i = 1
GroupDomain = "domain"
'GroupDomain = InputBox ("Domain to use for information:","Enter GroupDomain")
'	if GroupDomain = "" then
'	wscript.quit
'	end if
'GroupName = "SupportCenter"
GroupName = InputBox ("Group Name to list Members:","Enter GroupName")
	if GroupName = "" then
	end if

Set Con = CreateObject("ADODB.Connection")
Set Com = CreateObject("ADODB.Command")
Con.Provider = "ADsDSOObject" 
Con.Open "Active Directory Provider"
Set Com.ActiveConnection = Con
Set RootDSE = GetObject("LDAP://RootDSE")
sPath = "LDAP://" & rootDSE.Get("defaultNamingContext")

Set ws = CreateObject ("Scripting.FileSystemObject")
Set w = ws.OpenTextFile (GroupName & " " & "members.txt", ForAppending, True)
Set Group = GetObject("WinNT://" & GroupDomain & "/" & GroupName & ",group")


For Each Member in Group.Members
		oDepartment = "select department from '"& sPath &"' WHERE samAccountname= '"& Member.Name &"'"
		Com.CommandText = oDepartment
		set sDepartment = Com.Execute
                            w.WriteLine i & ";" & Member.Name & ";" & Member.FullName & ";" & title & ";" & sDepartment(0) &";"
		i = i + 1
Wscript.Echo "Text file " & GroupName & " " & " members.txt contains the list of users in this group."

set RootDSE = nothing
Set Com = Nothing
Set Con = Nothing

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Maybe you should use Member.Title instead of title?!
Hi, change this line:
		oDepartment = "select department from '"& sPath &"' WHERE samAccountname= '"& Member.Name &"'"

Open in new window

to this:
		oDepartment = "select department,title from '"& sPath &"' WHERE samAccountname= '"& Member.Name &"'"

Open in new window

to add the title to the recordset as the second field, then change this line:
                            w.WriteLine i & ";" & Member.Name & ";" & Member.FullName & ";" & title & ";" & sDepartment(0) &";"

Open in new window

to this
                            w.WriteLine i & ";" & Member.Name & ";" & Member.FullName & ";" & sDepartment(1) & ";" & sDepartment(0) &";"

Open in new window

so that you are outputting the second field as well.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Not sure if you got that message since EE went down just as I posted it.....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.