Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Get all the contacts and all the groups they are in.

Hi,

I want a way to just get the contacts and all the groups they are a member.Any way to fetch just these details with the OU path.
If they are a member of a root Domain then even that has to be displayed.
Regards
Sharath
Avatar of A2the6th
A2the6th

As far as I know there is no free tool to do this.  You could use a tool called Enterprise Security Reporter from Scriptlogic.  

That would allow you to report against a given OU and show each user or contact in this case and all of their associated group memberships.

Cheers
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Sharath,

Try this script.........
Option Explicit

Dim objRootDSE, strDNSDomain, objCommand, objConnection
Dim strBase, strFilter, strAttributes, strQuery, objRecordSet
Dim strNTName, strDN, objMemberof, strlist, objgroup

' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on contacts
strFilter = "(&(&(& (mailnickname=*)(| (&(objectCategory=person)(objectClass=contact)) ))))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "cn,distinguishedName,adspath,memberOf"

' Construct the ADO query, using LDAP syntax.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

' Run the query.
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute

' Enumerate the recordset and output the values retrieved in
' comma delimited format.
Do Until objRecordSet.EOF
strNTName = objRecordSet.Fields("cn").Value
strDN = objRecordSet.Fields("distinguishedName").Value

objMemberof = objRecordSet.Fields("memberof").Value
on error resume next
Strlist =""
For each objgroup in objmemberof
strlist = Strlist & objgroup & vbcrlf
Next

Wscript.Echo strNTName & "," & strDN & "," & "Groups:" & strlist

objRecordSet.MoveNext
Loop
objRecordSet.Close

' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
'============
Sorry Sharath,

I had this question open for a long time and i didn't see that the answer was accepted

regards
Chandru
Avatar of bsharath

ASKER

Chandru no problem.
I just checked your script it works fine...
Thanks Sharath for testing the script.

Sharath wanted to ask you where do you stay in Chennai as i had  a friend named "Sharath" when i did my college.

Cheers
Chandru
I stay in Perungudi.But i did all my schooling and college in Bangalore
Thanks for Clearning this......
:-)

regards
Chandru