[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Active Directory vb code filter by group

Posted on 2012-08-15
3
Medium Priority
?
573 Views
Last Modified: 2012-08-15
My following code returns a collection but

a.  It's slower than molasses on a Maine winter day
b. I can't seem to figure out how to filter on groups.

Example...I want to see all the people in the "Payroll" grop...etc...

 Public Shared Function FindADUsersInGroup(ByVal _group As String) As SearchResultCollection
        Dim dirEntry As DirectoryEntry = New DirectoryEntry(System.Configuration.ConfigurationManager.AppSettings("StrConnAD"))
        Dim DirSearcher As New DirectorySearcher()
        DirSearcher.PropertiesToLoad.Add("SAMAccountName")
        DirSearcher.PropertiesToLoad.Add("displayName")
        DirSearcher.PropertiesToLoad.Add("cn")
        DirSearcher.PropertiesToLoad.Add("group")
        DirSearcher.PropertiesToLoad.Add("title")
        DirSearcher.PropertiesToLoad.Add("memberOf")
        'DirSearcher.Filter = String.Format("(&(objectClass=user)(group={0}))", _group)
        Dim src As SearchResultCollection = DirSearcher.FindAll()

        If src Is Nothing Then
            Return Nothing
        Else
            Return src
        End If
    End Function

Open in new window

0
Comment
Question by:lrbrister
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Seaton007 earned 2000 total points
ID: 38296416
Here are several scripts for these types of operations: http://www.activexperts.com/network-monitor/windowsmanagement/adminscripts/usersgroups
0
 

Author Comment

by:lrbrister
ID: 38296661
Well...
The following code gets me a single line ...it returns the group


I need all the USERS in the group

    Public Shared Function FindADUsersInGroup(ByVal _group As String) As SearchResultCollection
        Dim dirEntry As DirectoryEntry = New DirectoryEntry(System.Configuration.ConfigurationManager.AppSettings("StrConnAD"))
        Dim DirSearcher As New DirectorySearcher()

        DirSearcher.PropertiesToLoad.Add("SAMAccountName")
        DirSearcher.PropertiesToLoad.Add("displayName")
        DirSearcher.PropertiesToLoad.Add("cn")
        DirSearcher.PropertiesToLoad.Add("group")
        DirSearcher.PropertiesToLoad.Add("title")
        DirSearcher.PropertiesToLoad.Add("memberOf")
        DirSearcher.PropertiesToLoad.Add("userPrincipalName")
        DirSearcher.PropertiesToLoad.Add("mail")

        DirSearcher.Filter = "(&(ObjectClass=Group)(CN=!Payroll))"
        Dim src As SearchResultCollection = DirSearcher.FindAll()

        If src Is Nothing Then
            Return Nothing
        Else
            Return src
        End If
    End Function

Open in new window

0
 

Author Closing Comment

by:lrbrister
ID: 38296764
Had to build a loop
Used your link as a reference
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month17 days, 22 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question