• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 19347
  • Last Modified:

List members of Active Directory group

I need a vbs script that list all the users in a global domain group. I need the script to create a file with the members usernames and full names. The group is a global security group I have made my self.
2 Solutions
Malli BoppeCommented:
The below script should get you all the groups and their members in the domain

Option Explicit

Dim objConnection, objCommand, objRecordSet, objGroup, objRootDSE,objFile, objFileSystem, objMember
Dim strLine

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.OpenTextFile("Groups.xls", 2, True, 0)
objFile.WriteLine "Group Name" & VbTab & "Number of Members" & VbTab & "Members"

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT name, aDSPath,mail " &_
      "FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & "' WHERE objectClass='group'"
Set objRootDSE = Nothing

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
      Set objGroup = GetObject(objRecordSet.Fields("aDSPath"))
            strLine = objRecordSet.Fields("name") & VbTab
            strLine = strLine & objGroup.Members.Count & VbTab

            For Each objMember in objGroup.Members
                  strLine = strLine & objMember.Get("name") & ","

            If Right(strLine, 1) = "," Then
                  strLine = Left(strLine, Len(strLine) - 1)
            End If
            objFile.WriteLine strLine
      Set objGroup = Nothing

Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

Set objFile = Nothing
Set objFileSystem = Nothing
Shanmuga SundaramDirector of Software EngineeringCommented:
Is this are you searching for

Dim objfso
Dim objfile
strDomain = "vakdomain"
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objfile = objfso.OpenTextFile("c:\results.txt", 2, True, 0)
Set colAccounts = GetObject("WinNT://" & strDomain & "")
colAccounts.Filter = Array("user")
objfile.writeline "User Full name                                    User Name"
For Each objuser In colAccounts
      objfile.writeline objuser.fullName & "                    " & objuser.Name
objfile.writeline "End of users"
crayonasAuthor Commented:
The sollution that you come with is almost what I need shasunder.. If you could help me adjust the script so that only the users of the group "TS_JobTech" is listed I would be very happy !

Thank you !

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now