bsharath
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("defaultNam ingContext ")
' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Comman d")
Set objConnection = CreateObject("ADODB.Connec tion")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnectio n = objConnection
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on contacts
strFilter = "(&(&(& (mailnickname=*)(| (&(objectCategory=person)( objectClas s=contact) ) ))))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "cn,distinguishedName,adsp ath,member Of"
' Construct the ADO query, using LDAP syntax.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
' Run the query.
objCommand.CommandText = strQuery
objCommand.Properties("Pag e Size") = 100
objCommand.Properties("Tim eout") = 30
objCommand.Properties("Cac he 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("disti nguishedNa me").Value
objMemberof = objRecordSet.Fields("membe rof").Valu e
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
'============
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("defaultNam
' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Comman
Set objConnection = CreateObject("ADODB.Connec
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnectio
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on contacts
strFilter = "(&(&(& (mailnickname=*)(| (&(objectCategory=person)(
' Comma delimited list of attribute values to retrieve.
strAttributes = "cn,distinguishedName,adsp
' Construct the ADO query, using LDAP syntax.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
' Run the query.
objCommand.CommandText = strQuery
objCommand.Properties("Pag
objCommand.Properties("Tim
objCommand.Properties("Cac
Set objRecordSet = objCommand.Execute
' Enumerate the recordset and output the values retrieved in
' comma delimited format.
Do Until objRecordSet.EOF
strNTName = objRecordSet.Fields("cn").
strDN = objRecordSet.Fields("disti
objMemberof = objRecordSet.Fields("membe
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
I had this question open for a long time and i didn't see that the answer was accepted
regards
Chandru
ASKER
Chandru no problem.
I just checked your script it works fine...
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
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
ASKER
I stay in Perungudi.But i did all my schooling and college in Bangalore
Thanks for Clearning this......
:-)
regards
Chandru
:-)
regards
Chandru
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