© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
5 replies
reeeeeee

Iterate over AD users and find some properties (EmployeeNumber, ExtensionAttributes, manager,..)

Basically all in the title. I would like to connect to local AD server, and sync some user information.

Currently I have this, but it doesnt have the properties mentioned in the title

using (var principalContext = new PrincipalContext(ContextType.Domain))
{
    var userPrinciple = new UserPrincipal(principalContext);
    // Performe search for Domain users
    using (var searchResult = new PrincipalSearcher(userPrinciple))
    {
        var allUsers = searchResult.FindAll();
           ...... process data....      

    }
}

using (var principalContext = new PrincipalContext(ContextType.Domain))
{
    var userPrinciple = new UserPrincipal(principalContext);
    // Performe search for Domain users
    using (var searchResult = new PrincipalSearcher(userPrinciple))
    {
        var allUsers = searchResult.FindAll();
           ...... process data....      

    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Iterate over a range
C#CC# / help
3y ago
Iterate through Enums
C#CC# / help
15mo ago
OOP - Properties and Fields
C#CC# / help
13mo ago
Virtual and virtual properties
C#CC# / help
2y ago