Get SAMAccountNames for all users in an active directory group



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

.



Relevant Pages

  • Active Directory gives up group info for only SOME users
    ... Our ASP.NET app is secured with forms authentication and validates users ... against Active Directory. ... Private _filterAttribute As String ... Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, ...
    (microsoft.public.dotnet.security)
  • AD only gives up group (role) information for SOME users
    ... Our ASP.NET app is secured with forms authentication and validates users ... against Active Directory. ... Private _filterAttribute As String ... Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Need assistance badly!
    ... I have tried cobbling together a script that does this, ... I would use ADO in a VBScript program to retrieve all users with the ... Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN ... adoConnection.Open "Active Directory Provider" ...
    (microsoft.public.scripting.vbscript)
  • ADSI Authentication Problem in ASP
    ... I've one system in which Active directory is installed. ... That system is the domain controller as well as web ... I need ASP solution. ... Dim oDSObj As IADsOpenDSObject ...
    (microsoft.public.inetserver.asp.general)
  • ADSI Authentication using ASP - Problem
    ... I've one system in which Active directory is installed. ... That system is the domain controller as well as web ... I need ASP solution. ... Dim oDSObj As IADsOpenDSObject ...
    (microsoft.public.inetserver.iis.security)

Loading