dbTalk Databases Forums  

access2007, get users in active directory group

comp.databases.ms-access comp.databases.ms-access


Discuss access2007, get users in active directory group in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roger
 
Posts: n/a

Default access2007, get users in active directory group - 01-17-2011 , 04:34 PM






this vba wil get me a list of contacts, and changing the object class
to 'user' will give a list of users from AD
is there a way to get a list of users in a security group ?
distribution group ?


Dim objConnection As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim objCommand As New ADODB.Command

objConnection.Provider = "adsdsoobject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Sort On") = "Name"
objCommand.CommandText = "SELECT *" & _
" FROM 'LDAP://OU=foo,DC=bar,DC=com'" &
_
" WHERE objectCategory ='person'" & _
" AND objectClass = 'contact'"
Set rs = objCommand.Execute
While (Not (rs.EOF))
Debug.Print rs!ADSPATH
rs.MoveNext
Wend

Reply With Quote
  #2  
Old   
Roger
 
Posts: n/a

Default Re: access2007, get users in active directory group - 01-17-2011 , 04:47 PM






On Jan 17, 3:34*pm, Roger <lesperan... (AT) natpro (DOT) com> wrote:
Quote:
this vba wil get me a list of contacts, and changing the object class
to 'user' will give a list of users from AD
is there a way to get a list of users in a security group ?
distribution group ?

* * Dim objConnection As New ADODB.Connection
* * Dim rs As ADODB.Recordset
* * Dim objCommand As New ADODB.Command

* * objConnection.Provider = "adsdsoobject"
* * objConnection.Open "Active Directory Provider"
* * Set objCommand.ActiveConnection = objConnection
* * objCommand.Properties("Page Size") = 1000
* * objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
* * objCommand.Properties("Sort On") = "Name"
* * objCommand.CommandText = "SELECT *" & _
* * * * * * * * * * * * * * *" *FROM 'LDAP://OU=foo,DC=bar,DC=com'" &
_
* * * * * * * * * * * * * * *" WHERE objectCategory ='person'" & _
* * * * * * * * * * * * * * *" * AND objectClass = 'contact'"
* * Set rs = objCommand.Execute
* * While (Not (rs.EOF))
* * * * Debug.Print rs!ADSPATH
* * * * rs.MoveNext
* * Wend
use this command text will enumerate the groups
objCommand.CommandText = "SELECT *" & _
" FROM 'LDAP://OU=foo,DC=bar,DC=com'" &
_
" WHERE objectCategory ='group'" & _
" AND objectClass = '*'"

but I'm still looking to enumerate the users in a specific group

Reply With Quote
  #3  
Old   
Roger
 
Posts: n/a

Default Re: access2007, get users in active directory group - 01-18-2011 , 07:01 AM



On Jan 17, 3:47*pm, Roger <lesperan... (AT) natpro (DOT) com> wrote:
Quote:
On Jan 17, 3:34*pm, Roger <lesperan... (AT) natpro (DOT) com> wrote:





this vba wil get me a list of contacts, and changing the object class
to 'user' will give a list of users from AD
is there a way to get a list of users in a security group ?
distribution group ?

* * Dim objConnection As New ADODB.Connection
* * Dim rs As ADODB.Recordset
* * Dim objCommand As New ADODB.Command

* * objConnection.Provider = "adsdsoobject"
* * objConnection.Open "Active Directory Provider"
* * Set objCommand.ActiveConnection = objConnection
* * objCommand.Properties("Page Size") = 1000
* * objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
* * objCommand.Properties("Sort On") = "Name"
* * objCommand.CommandText = "SELECT *" & _
* * * * * * * * * * * * * * *" *FROM 'LDAP://OU=foo,DC=bar,DC=com'" &
_
* * * * * * * * * * * * * * *" WHERE objectCategory ='person'" & _
* * * * * * * * * * * * * * *" * AND objectClass = 'contact'"
* * Set rs = objCommand.Execute
* * While (Not (rs.EOF))
* * * * Debug.Print rs!ADSPATH
* * * * rs.MoveNext
* * Wend

use this command text will enumerate the groups
* * objCommand.CommandText = "SELECT *" & _
* * * * * * * * * * * * * * *" *FROM 'LDAP://OU=foo,DC=bar,DC=com'" &
_
* * * * * * * * * * * * * * *" WHERE objectCategory ='group'" & _
* * * * * * * * * * * * * * *" * AND objectClass = '*'"

but I'm still looking to enumerate the users in a specific group- Hide quoted text -

- Show quoted text -
this seems to work
Sub t2()
Dim strAttributes As String
Dim strFilter As String
Dim strScope As String
Dim strRoot As String
Dim objRoot As Object
Dim cmd As ADODB.Command
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

strAttributes =
"samAccountName,GivenName,SN,Title,TelephoneNumber ,Mobile,Pager,HomePhone"
strFilter = "(&(objectCategory=person)(MemberOf=CN=IT
Group,OU=foo,DC=bar,DC=com))"
strScope = "subtree"

Set cmd = CreateObject("ADODB.Command")
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open "Provider=ADsDSOObject;"
cmd.activeconnection = cn

Set objRoot = GetObject("LDAP://RootDSE")
strRoot = objRoot.Get("defaultNamingContext")

cmd.CommandText = "<LDAP://" & strRoot & ">;" & strFilter & ";" &
strAttributes & ";" & strScope
cmd.Properties("page size") = 1000
Set rs = cmd.Execute
While Not (rs.EOF)
debug.print rs!samAccountName
rs.MoveNext
Wend

cn.Close
End Sub

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.