src/libraries/System.DirectoryServices.AccountManagement/src/PACKAGE.md
Provides uniform access and manipulation of security principals across multiple principal stores. The principal objects in the Account Management API include computer, group and user objects. The principal stores includes:
// Create the principal context for the usr object.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "fabrikam.com", "CN=Users,DC=fabrikam,DC=com", "administrator", "securelyStoredPassword");
// Create the principal user object from the context.
UserPrincipal usr = new UserPrincipal(ctx);
usr.AdvancedSearchFilter.LastLogonTime(DateTime.Now, MatchType.LessThan);
usr.AdvancedSearchFilter.LastLogonTime(DateTime.Yesterday, MatchType.GreaterThan);
// Create a PrincipalSearcher object.
PrincipalSearcher ps = new PrincipalSearcher(usr);
PrincipalSearchResult<Principal> fr = ps.FindAll();
foreach (UserPrincipal u in results)
{
Console.WriteLine(u.Name);
}
The main types provided by this library are:
System.DirectoryServices.AccountManagement.PrincipalContextSystem.DirectoryServices.AccountManagement.PrincipalSearcherSystem.DirectoryServices.AccountManagement.Principal and its subclasses: System.DirectoryServices.AccountManagement.UserPrincipal, System.DirectoryServices.AccountManagement.GroupPrincipal and System.DirectoryServices.AccountManagement.ComputerPrincipalSystem.DirectoryServices.AccountManagement is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.