Description: A .NET Standard C# class library exposing Active Directory data. This class library can be used in any Windows .NET Standard 2.0+, .NET Framework 4.6.1+, or .NET/.NET Core 2.0+ based projects.
- Maintainers:
- Clone the repository to your computer.
- Or, Download the files to your computer.
- Or, Download package from NuGet.org.
- Using Visual Studio 2022 or higher, open project solution .
- On the menu, click Build > Build Solution
- After the solution builds successfully.
using (var adSearcher = new ADSearcher("GC://DC=example,DC=com"))
{
string username = "XXXDOEJ";
var adUser = adSearcher.GetADUserBySamAccountName(username);
Console.WriteLine(adUser.DisplayName);
}
using (var adSearcher = new ADSearcher("GC://DC=example,DC=com"))
{
string email = "[email protected]";
var adUser = adSearcher.GetADUserByEmail(email);
Console.WriteLine(adUser.DisplayName);
}
using (var adSearcher = new ADSearcher("GC://DC=example,DC=com"))
{
string username = "XXXDOEJ";
var adUser = adSearcher.GetADUserManagerBySamAccountName(username);
Console.WriteLine(adUser.DisplayName);
Console.WriteLine(adUser.Manager.DisplayName);
}
using (var adSearcher = new ADSearcher("GC://DC=example,DC=com"))
{
string firstName = "jan";
string lastName = "doe";
var adUsers = adSearcher.GetADUsersByNameSearch(firstName, lastName).ToList();
ADUser firstPerson = adUsers[0];
Console.WriteLine(firstPerson.DisplayName);
}
Retrieving custom Active Directory information for a Person using Partial First and Last Name search
using (var adSearcher = new ADSearcher("GC://DC=example,DC=com"))
{
string firstName = "jane";
string lastName = "doe";
string filter = $"(&(objectClass=user)(sn={lastName.Trim()}*)(givenName={firstName.Trim()}*))";
string[] propertiesToLoad = ["distinguishedName", "mail", "displayName"];
var results = adSearcher.GetSeachResultCollection(filter, propertiesToLoad);
// string firstDisplayName = results[0].Properties["displayName"][0].ToString();
string firstDisplayName = ADHelper.GetAdProperty(results, "displayName");
Console.WriteLine(firstDisplayName);
}