Re: Get SAMAccountNames for all users in an active directory group
- From: "Joe Kaplan" <joseph.e.kaplan@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 20 Jan 2008 21:59:00 -0600
Yep, this is a good use for attribute scope query. There is a .NET code
sample from ch. 5 of our book which can be downloaded from our book's
website (see link below).
Most of the time, in situations where you could to an ASQ, you can simply do
the search "backwards". For example, you can search for all objects that
have memberOf = the DN of the group in question and return the
sAMAccountName and this will do the same basic thing as an ASQ would.
Joe K.
--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
"Dean Wells (MVP)" <dwells@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23H2SWgsWIHA.3400@xxxxxxxxxxxxxxxxxxxxxxx
Do some digging on an LDAP control/feature called 'attribute scoped
queries' ... this will do as you ask in a single (from the client-side at
least) query.
--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R a m o v e t h e m a s k t o s e n d e m a i l
<psychrodraconic@xxxxxxxxx> wrote in message
news:c8a43f19-50d0-48ee-b655-58f14e1f5e98@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am trying to get a list of NT Login Names (SAMAccountNames) for the
users that belong to an active directory group. I have a function
that is used for receiving a list of the members of a group. This
works perfectly for getting the members. However, not so much for
getting the SAMAccountNames. Could anyone give me any guidance on how
to get the account names for a group in active directory?
Below is a sample method for getting the members for that group.
Public Shared Function getGroupMembers(ByVal group As String)
As ArrayList
Dim Members As ArrayList = New ArrayList()
Dim _path As String =
ConfigurationManager.AppSettings("ADConnectionString")
'------ Start Impersonation ------
Dim ImpersonateContext As WindowsImpersonationContext =
Utilities.Impersonate(LDAPuser, LDAPpassword, LDAPdomain)
'------ Start running code -------
Dim entry As DirectoryEntry = New DirectoryEntry(_path,
LDAPdomain + "\" + LDAPuser, LDAPpassword,
AuthenticationTypes.ServerBind)
Dim search As DirectorySearcher = New
DirectorySearcher(entry)
search.Filter = "(cn=" & group & ")"
search.PropertiesToLoad.Add("member")
Dim result As SearchResult = search.FindOne()
If Not (result Is Nothing) Then
Dim propertyCount As Integer =
result.Properties("member").Count
Dim equalsIndex, commaIndex As Integer
Dim user As String
For counter As Integer = 0 To propertyCount - 1
user = result.Properties("member")
(counter).ToString
equalsIndex = user.IndexOf("=", 1)
commaIndex = user.IndexOf(",", 1)
If Not (equalsIndex = -1) Then
Members.Add(user.Substring((equalsIndex + 1),
(commaIndex - equalsIndex) - 1))
End If
Next
End If
'------ End Impersonation ------
ImpersonateContext.Undo()
Members.Sort()
Return Members
End Function
.
- Follow-Ups:
- Re: Get SAMAccountNames for all users in an active directory group
- From: psychrodraconic@xxxxxxxxx
- Re: Get SAMAccountNames for all users in an active directory group
- References:
- Get SAMAccountNames for all users in an active directory group
- From: psychrodraconic@xxxxxxxxx
- Re: Get SAMAccountNames for all users in an active directory group
- From: Dean Wells \(MVP\)
- Get SAMAccountNames for all users in an active directory group
- Prev by Date: Re: domain name/LDAP redundancy
- Next by Date: Re: domain name/LDAP redundancy
- Previous by thread: Re: Get SAMAccountNames for all users in an active directory group
- Next by thread: Re: Get SAMAccountNames for all users in an active directory group
- Index(es):
Relevant Pages
|