This script will list all users in a specific active directory security group in a csv file. The csv file will be created in what ever directory the script is executed from. Before using the script line 22 will need to be modified to identify your domain name. The csv file will have one user per line with their username, first and last name, department and title.
As always use this script at your own risk.
Option Explicit Dim Group Dim GroupName Dim GroupDomain Dim Member 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 = "DomainName" '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 wscript.quit 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") w.WriteLine i & "; USER ID; USER NAME; DEPARTMENT; TITLE;" For Each Member in Group.Members oDepartment = "select department,title from '"& sPath &"' WHERE samAccountname= '"& Member.Name &"'" 'oDepartment = "select department from '"& sPath &"' WHERE samAccountname= '"& Member.Name &"'" Com.CommandText = oDepartment set sDepartment = Com.Execute w.WriteLine i & ";" & Member.Name & ";" & Member.FullName & ";" & sDepartment(1) & ";" & sDepartment(0) &";" 'w.WriteLine i & ";" & Member.Name & ";" & Member.FullName &";" & sDepartment(0) &";" i = i + 1 Next Wscript.Echo "Text file " & GroupName & " " & " members.txt contains the list of users in this group." set RootDSE = nothing Set Com = Nothing Set Con = Nothing