Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:29:18+00:00 2026-05-30T18:29:18+00:00

I’ve successfully used the AccountManagement code to retrieve basic AD information but it’s only

  • 0

I’ve successfully used the AccountManagement code to retrieve basic AD information but it’s only returning a very limited set of information about the returned object. How can I get extended information from AD using the AccountManagement functionality. Specifically the Job Title or title as it seems to be called in my instance of AD.

I know how to do it using the older DirectoryServices but I’d like to know how to do it using the new namespace.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:29:20+00:00Added an answer on May 30, 2026 at 6:29 pm

    Yes, the default set of properties on UserPrincipal is quite limited – but the great part is: there’s a neat extensibility story in place!

    You need to define a class descending from UserPrincipal and then you can very easily get access to a lot more properties, if needed.

    The skeleton would look something like this:

    namespace ADExtended
    {
        [DirectoryRdnPrefix("CN")]
        [DirectoryObjectClass("User")]
        public class UserPrincipalEx : UserPrincipal
        {
            // Inplement the constructor using the base class constructor. 
            public UserPrincipalEx(PrincipalContext context) : base(context)
            { }
    
            // Implement the constructor with initialization parameters.    
            public UserPrincipalEx(PrincipalContext context,
                                 string samAccountName,
                                 string password,
                                 bool enabled) : base(context, samAccountName, password, enabled)
            {} 
    
            UserPrincipalExSearchFilter searchFilter;
    
            new public UserPrincipalExSearchFilter AdvancedSearchFilter
            {
                get
                {
                    if (null == searchFilter)
                        searchFilter = new UserPrincipalExSearchFilter(this);
    
                    return searchFilter;
                }
            }
    
            // Create the "Title" property.    
            [DirectoryProperty("title")]
            public string Title
            {
                get
                {
                    if (ExtensionGet("title").Length != 1)
                        return string.Empty;
    
                    return (string)ExtensionGet("title")[0];
                }
                set { ExtensionSet("title", value); }
            }
    
            // Implement the overloaded search method FindByIdentity.
            public static new UserPrincipalEx FindByIdentity(PrincipalContext context, string identityValue)
            {
                return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityValue);
            }
    
            // Implement the overloaded search method FindByIdentity. 
            public static new UserPrincipalEx FindByIdentity(PrincipalContext context, IdentityType identityType, string identityValue)
            {
                return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityType, identityValue);
            }
        }
    }
    

    And that’s really almost all there is! The ExtensionGet and ExtensionSet methods allow you to “reach down” into the underlying directory entry and grab out all the attributes you might be interested in….

    Now, in your code, use your new UserPrincipalEx class instead of UserPrincipal:

    using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
    {
        // Search the directory for the new object. 
        UserPrincipalEx myUser = UserPrincipalEx.FindByIdentity(ctx, "someUserName");
    
        if(myUser != null)
        { 
            // get the title which is now available on your "myUser" object!
            string title = myUser.Title;
        }
    }
    

    Read all about the System.DirectoryServices.AccountManagement namespace and its extensibility story here:

    • Managing Directory Security Principals in the .NET Framework 3.5

    Update: sorry – here’s the UserPrincipalExSearchFilter class – missed that one in the original post. It just shows the ability to also extend the search filters, if need be:

    public class UserPrincipalExSearchFilter : AdvancedFilters
    {
        public UserPrincipalExSearchFilter(Principal p) : base(p) { }
    
        public void LogonCount(int value, MatchType mt)
        {
            this.AdvancedFilterSet("LogonCount", value, typeof(int), mt);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.