DirectorySearcher Class

Performs queries against Active Directory.

Namespace: System.DirectoryServices
Assembly: System.DirectoryServices (in system.directoryservices.dll)

public class DirectorySearcher : Component
public class DirectorySearcher extends Component
public class DirectorySearcher extends Component
Not applicable.

Use a DirectorySearcher object to search and perform queries against an Active Directory hierarchy using Lightweight Directory Access Protocol (LDAP). LDAP is the only system-supplied Active Directory Service Interfaces (ADSI) provider that supports directory searching. An administrator can make, alter, and delete objects that are found in the hierarchy. For more information, see Using System.DirectoryServices.

When you create an instance of DirectorySearcher, you specify the root you want to retrieve, and an optional list of properties to retrieve. The SearchRoot property enables you to set additional properties to do the following tasks:

  • Cache the search results on the local computer. Set the CacheResults property to true to store directory information on the local computer. Updates are made to this local cache and committed to Active Directory only when the DirectoryEntry.CommitChanges method is called.

  • Specify the length of time to search, using the ServerTimeLimit property.

  • Retrieve attribute names only. Set the PropertyNamesOnly property to true to retrieve only the names of attributes to which values have been assigned.

  • Perform a paged search. Set the PageSize property to specify the maximum number of objects that are returned in a paged search. If you do not want to perform a paged search, set the PageSize property to its default of zero.

  • Specify the maximum number of entries to return, using the SizeLimit property. If you set the SizeLimit property to its default of zero, the server-determined default is 1000 entries.


If the maximum number of returned entries and time limits exceed the limitations that are set on the server, the server settings override the component settings.

For a list of initial property values for an instance of the DirectorySearcher class, see the DirectorySearcher constructor.


It is assumed that you have a general understanding of Active Directory before using this class. For more information, see the System.DirectoryServices overview.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0