System.DirectoryServices.AccountManagement question! RRS feed

  • Question

  • User1892209985 posted


    I am attempting to rewrite some old C# code in our code base that utilized DirectoryEntry to perform some LDAP queries. I am migrating it to the new System.DirectoryServices.AccountManagement namespace and have done about 90% of it, but one key aspect is still not done, and I stuck...

    I am attempting to access some custom ActiveDirectory fields, one being EmployeeNumber and for the life of me can't figure out how... Anyone have any clue how to access these custom fields using the System.DirectoryServices.AccountManagement namespace?

    Wednesday, May 20, 2009 10:03 PM

All replies

  • User1892209985 posted

    I can't be the first person to attempt this :)

    Bueller... Bueller... :)

    Thursday, May 28, 2009 8:39 PM
  • User1892209985 posted

     ok... After some digging this weekend I read that you can extend these classes pretty easily (that is what read...), and I think this is the solution here:


     I have created the class for my custom AdvancedFilter but have no idea how to use it!

    Getting closer though...

    Sunday, May 31, 2009 10:48 PM
  • User-145451702 posted


    Am having the same problem, I have not just one, but many custom attributes / properties added into Active Directory, now I need to know how to insert / modify the values of custom properties in active directory using AccountManagement API.

    Please let me know, If you have found the soultion this problem


    Thanks a million in Advance.


    Saturday, August 29, 2009 5:46 AM
  • User1095185381 posted

    Try the bottom of this article: Managing Directory Security Principals in the .NET Framework 3.5  (http://msdn.microsoft.com/en-us/magazine/cc135979.aspx#S10)

    Saturday, September 26, 2009 11:48 AM
  • User-540912603 posted

    You need to fall back on DirectoryServices by getting the underlying object (DirectoryEntry) of you principal and then setting any property you want.

    I posted about this here: http://www.teebot.be/2009/12/ad-setting-custom-properties-using-new.html 


    public void SetCustomProperty<T>(string key, string value, T principal) where T : Principal
                if (principal.GetUnderlyingObjectType() == typeof(DirectoryEntry))
                    DirectoryEntry entry = (DirectoryEntry)principal.GetUnderlyingObject();
                    entry.Properties[key].Value = value;
                    catch (Exception e)
                        string message = String.Format("Could not set custom property {0} to value {1} for object {2}", key, value, principal.Name);
                        throw new Exception(message, e);





    Wednesday, December 16, 2009 7:41 AM