Help extrracting members from a group?

N

Nimag

Dear all

i hope this is not covered already in another post, if so please just
put reply with the link. I am looking for a way of extracting all the
distribution groups from Active Directory and listing all the users
for each group. Below is the code that I have half working, if anyone
can point me in the right direction that would be very much
appriceated

Sub ADSearch(domStr As String, aspStr As String, sysAcc As String)

Const ADS_SCOPE_SUBTREE = 2
Range("A1").Select


Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE



On Error Resume Next

objCommand.CommandText = "SELECT Name, DisplayName,ManagedBy FROM
'LDAP:// dc=GTC, dc=Ori, dc=local' WHERE objectCategory='group'" & _
"AND groupType = 8 or groupType = 4"



Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
x = 0
Do Until objRecordSet.EOF
Cells(1, x).Value = objRecordSet.Fields("NAME").Value
Cells(2, x).Value = objRecordSet.Fields("DisplayName").Value
'Cells(x, 3).Value = objRecordSet.Fields("ManagedBy").Value
x = x + 1
objRecordSet.MoveNext

Loop

'Retreiving all the users in each group THIS IS THE ASPECT THAT
DOES NOT WORK
'ANY HELP GETTING THIS WORK.
objCommand.CommandText = "SELECT * FROM 'LDAP:// dc=GTC, dc=Ori,
dc=local'" & _
"WHERE objectCategory='group' AND groupName='ArtworkTeam'"
Set objRecordSetMembers = objCommand.Execute



y = 2
Do Until objRecordSetMembers.EOF
Cells(y, 1).Value = objRecordSetMembers.Fields
("Member").Value
y = y + 1
objRecordSetMembers.MoveNext

Loop

'Auto fiting the columns
For x = 1 To 3
Cells(1, x).Select
ActiveCell.EntireColumn.AutoFit
Next x

frmMain.Hide

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top