Get SAMAccountNames for all users in an active directory group
- From: "psychrodraconic@xxxxxxxxx" <psychrodraconic@xxxxxxxxx>
- Date: Fri, 18 Jan 2008 13:35:39 -0800 (PST)
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: Richard Mueller [MVP]
- Re: Get SAMAccountNames for all users in an active directory group
- From: Dean Wells \(MVP\)
- Re: Get SAMAccountNames for all users in an active directory group
- Prev by Date: Re: Active Directory domain rename and Cisco Unity
- Next by Date: Re: Distinguished Name -- order is important?
- Previous by thread: Re: Active Directory domain rename and Cisco Unity
- Next by thread: Re: Get SAMAccountNames for all users in an active directory group
- Index(es):
Relevant Pages
|
Loading