Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
 FindAll Method
Collapse All/Expand All Collapse All
.NET Framework Class Library
DirectorySearcher..::.FindAll Method

Executes the search and returns a collection of the entries that are found.

Namespace:  System.DirectoryServices
Assembly:  System.DirectoryServices (in System.DirectoryServices.dll)
Visual Basic
Public Function FindAll As SearchResultCollection
C#
public SearchResultCollection FindAll()
Visual C++
public:
SearchResultCollection^ FindAll()
F#
member FindAll : unit -> SearchResultCollection 

Return Value

Type: System.DirectoryServices..::.SearchResultCollection
A SearchResultCollection object that contains the results of the search.
ExceptionCondition
InvalidOperationException

The specified DirectoryEntry is not a container.

NotSupportedException

Searching is not supported by the provider that is being used.

Due to implementation restrictions, the SearchResultCollection class cannot release all of its unmanaged resources when it is garbage collected. To prevent a memory leak, you must call the Dispose method when the SearchResultCollection object is no longer needed.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Return value      Strikah   |   Edit   |   Show History
In PowerShell, this method returns a SearchResult object if only one object is found, instead of a SearchResultCollection. If you want to check the number of returned objects via the Count property of SearchResultCollection, you need to code around this if the search might return only one object.
Tags What's this?: Add a tag
Flag as ContentBug
Remember Pagesize      Pilot Mike   |   Edit   |   Show History
this will only return the first 1000 items unless you set the pagesize.
Tags What's this?: Add a tag
Flag as ContentBug
Example of use      scienco   |   Edit   |   Show History
            // Connect to LDAP

            AuthenticationTypes authTypes; // Authentication flags.
            authTypes = AuthenticationTypes.Signing | AuthenticationTypes.Sealing | AuthenticationTypes.Secure;

            string domainAndUsername = domain + @"\" + user;

            DirectoryEntry oAuthedEntry = new DirectoryEntry(ldapConnectionString, domainAndUsername, pwd, authTypes);

            // Create new DirectorySearcher instance
            DirectorySearcher search = new DirectorySearcher(oAuthedEntry);

           // Set search criteria

            search.Filter = "(objectCategory=user)";

            search.PropertiesToLoad.Add("displayName");                             // name
            search.PropertiesToLoad.Add("physicalDeliveryOfficeName");      // location
            search.PropertiesToLoad.Add("telephoneNumber");                    // phone number
            search.PropertiesToLoad.Add("mobile");                                     // mobile            
            search.PropertiesToLoad.Add("mail");                                        // email address
            search.PropertiesToLoad.Add("msDS-UserAccountDisabled");   // account status  
            search.PropertiesToLoad.Add("title");                                        // title
            search.PropertiesToLoad.Add("ms-DS-UserAccountAutoLocked");     // locked

            // Perform the search
            SearchResultCollection results = null;
            try
            {
                results = search.FindAll();
            }
            catch (Exception searchEx)
            {
                throw new Exception("Error obtaining users results. ", searchEx);
            }
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker