LDAP - Retrieve a list of all attributes/values? LDAP - Retrieve a list of all attributes/values? windows windows

LDAP - Retrieve a list of all attributes/values?


I grab list of all parameters my DirectoryEntry class object. I hope it will help:

objectClass = System.Object[]cn = Administratorsn = Kwiatek (Last name)c = PL (Country Code)l = Warszawa (City)st = Mazowieckie (Voivodeship)title = .NET Developerdescription = Built-in account for administering the computer/domainpostalCode = 00-000postOfficeBox = Warszawa UrsynówphysicalDeliveryOfficeName = Wojskowa Akademia TechnicznagivenName = Piotr (First name)distinguishedName = CN=Administrator,CN=Users,DC=helpdesk,DC=wat,DC=eduinstanceType = 4whenCreated = 2012-11-23 06:09:28whenChanged = 2013-02-23 13:24:41displayName = Piotr Kwiatek (Konto administratora)uSNCreated = System.__ComObjectmemberOf = System.Object[]uSNChanged = System.__ComObjectco = Polandcompany = HELPDESKstreetAddress = Kaliskiego 2wWWHomePage = http://www.piotr.kwiatek.orgname = AdministratorobjectGUID = System.Byte[]userAccountControl = 512badPwdCount = 0codePage = 0countryCode = 616badPasswordTime = System.__ComObjectlastLogoff = System.__ComObjectlastLogon = System.__ComObjectlogonHours = System.Byte[]pwdLastSet = System.__ComObjectprimaryGroupID = 513objectSid = System.Byte[]adminCount = 1accountExpires = System.__ComObjectlogonCount = 178sAMAccountName = AdministratorsAMAccountType = 805306368objectCategory = CN=Person,CN=Schema,CN=Configuration,DC=helpdesk,DC=wat,DC=eduisCriticalSystemObject = TruedSCorePropagationData = System.Object[]lastLogonTimestamp = System.__ComObjectmail = spam@kwiatek.orgnTSecurityDescriptor = System.__ComObject

And here You have code:

string currentUserSid = WindowsIdentity.GetCurrent().User.Value;            PrincipalContext ctx = new PrincipalContext(                ContextType.Domain,                "helpdesk.wat.edu");            UserPrincipal up = UserPrincipal.FindByIdentity(                ctx, IdentityType.Sid,                currentUserSid);            /*             *              */            DirectoryEntry entry = up.GetUnderlyingObject() as DirectoryEntry;            PropertyCollection props = entry.Properties;            /*             *              */            foreach (string propName in props.PropertyNames)            {                if (entry.Properties[propName].Value != null)                {                    Console.WriteLine(propName + " = " + entry.Properties[propName].Value.ToString());                }                else                {                    Console.WriteLine(propName + " = NULL");                }            }            Console.ReadKey();


Specify "*" as the only value in the list of attributes to return.

If you want the operational attributes as well, add "+" to the list.


    // This will list ALL the properties from AD (between 200 and 800..or more)    // If someone has a solution for non AD servers please post it!    List<String> properties = new List<String>();    IPAddress[] ips = Dns.GetHostAddresses(Server).Where(w => w.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToArray();    if (ips.Length > 0)    {        DirectoryContext directoryContext = new DirectoryContext(DirectoryContextType.DirectoryServer, ips[0].ToString() + ":389", Username, Password);        ActiveDirectorySchema adschema = ActiveDirectorySchema.GetSchema(directoryContext);        ActiveDirectorySchemaClass adschemaclass = adschema.FindClass("User");        // Read the OptionalProperties & MandatoryProperties        ReadOnlyActiveDirectorySchemaPropertyCollection propcol = adschemaclass.GetAllProperties();        foreach (ActiveDirectorySchemaProperty schemaProperty in propcol)            properties.Add(schemaProperty.Name.ToLower());    }