Obtaining Group and Member Information

  • 10 September 2004
  • 5 replies
  • 1 view

Badge +3
How can I obtain a list of groups, members of a group, and groups a user is a member of in the Active Directory so routing and approvals can be done dynamically depending on groups a user is a member of.

Thank you

5 replies

Badge +4
icon-quote.gifStevep:
How can I obtain a list of groups, members of a group, and groups a user is a member of in the Active Directory so routing and approvals can be done dynamically depending on groups a user is a member of.

Thank you


The System.DirectoryServices namespace contains the objects for accessing Active Directory. You can add a server event to an activity that uses this namespace to retrieve the necessary AD info.
Badge +3
"steven.hughes wrote:

The System.DirectoryServices namespace contains the objects for accessing Active Directory. You can add a server event to an activity that uses this namespace to retrieve the necessary AD info.

Thanks for the info...I've never done this...if you have an example, I'd appreciate seeing it...if not, I'll look it up and try it.

Thanks again

Steve
Badge +4
Add a reference to System.DirectoryServicess.dll to your K2 project.
Add an "Imports" to System.DirectoryServices to your K2 project.

This code was pulled from a sample stand-alone app (not a K2 process) and writes the membership of an Active Directory group to the console.


Private Sub GetMembers(sGroupPath as String)
Dim oGroup As DirectoryEntry
Dim sMember() As String
Dim nMember As Integer

Try
oGroup = New DirectoryServices.DirectoryEntry(sGroupPath)

Console.WriteLine("Members of " + sGroupPath + ": ")
If oGroup.Properties("Member").Count = 0 Then
Console.WriteLine(" There are no members in this group")
Else
For nMember = 0 To oGroup.Properties("Member").Count - 1
Console.WriteLine(" " +
oGroup.Properties("Member").Item(nMember).ToString)
Next nMember
End If

Catch ex As Exception
Console.WriteLine("Error in GetMembers() - " + ex.Message)
Return
Finally
If Not IsNothing(oGroup) Then oGroup.Close() : oGroup = Nothing
End Try
End Sub


Pass this function the adsPath of the group for which you need the membership. The adsPath will be something like "LDAP://CN=MyGroupName,OU=MyOUName,DC=MyDomain,DC=com".

If all you have is just the group's name and don't know where it is in the directory, use the System.DirectoryServices.DirectorySearcher class to find the group. From there, you can get a reference directly to the group (and if you want, you can also, retrieve the group's adsPath).
Badge +3
Thanks for the sample code. I'll try that and see how it works out.
Badge +3
Thanks for the sample code. I'll try that and see how it works out.

Reply