Skip to content

Latest commit

 

History

History
108 lines (76 loc) · 3.41 KB

README.md

File metadata and controls

108 lines (76 loc) · 3.41 KB

FEDDEVOSS.ActiveDirectoryHelper

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.

Table of Contents

Project Members

Getting Started

  1. Clone the repository to your computer.
  2. Or, Download the files to your computer.
  3. Or, Download package from NuGet.org.

Local Development

  1. Using Visual Studio 2022 or higher, open project solution .
  2. On the menu, click Build > Build Solution
  3. After the solution builds successfully.

Code Examples

Retrieving Active Directory information for a Person by Username

using (var adSearcher = new ADSearcher("GC://DC=example,DC=com"))
{
    string username = "XXXDOEJ";
    var adUser = adSearcher.GetADUserBySamAccountName(username);

    Console.WriteLine(adUser.DisplayName);
}

Retrieving Active Directory information for a Person by Email addreass

using (var adSearcher = new ADSearcher("GC://DC=example,DC=com"))
{
    string email = "[email protected]";
    var adUser = adSearcher.GetADUserByEmail(email);

    Console.WriteLine(adUser.DisplayName);
}

Retrieving Active Directory information for a Person with Supervisor information

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);
}

Retrieving 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 = "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);
}

Dependencies