简体   繁体   中英

Enumerate ALL properties of AD Object (even unset ones)

I'm trying to find several properties that aren't used anywhere in our AD environment. I don't care what the property name is as long as it isn't used.

I was attempting to do this in C# mainly so that I can explore those classes while I solved this problem, but can't seem to find a way to list all of the properties for an object. The DirectoryEntry.Properties returns a collection of set properties only (as far as I can tell).

So is it possible to view all the active (available) properties for an object or are you only able to view the ones that are currently set with a value somewhere?

EDIT: Current code...

using (var directoryObject = new DirectoryEntry("LDAP://CN=GroupCN,OU=groups,DC=domain,DC=com", "uid", "pass", AuthenticationTypes.ReadonlyServer)) {
    foreach (var prop in directoryObject.Properties.PropertyNames) {
        Console.WriteLine(prop.ToString() + " | " + directoryObject.Properties[prop.ToString()].Value.ToString());
    }
}

Edit: Ok. So I missed the bit about all possible properties. So I will address that.

Since the DirectoryEntry object is an implementation of IDictionary, there really is no way to know what properties can be set. IDictionary will allow you to add as many custom properties as you would like to the object. The documentation for System.DirectoryServices.Property collection is here: http://msdn.microsoft.com/en-us/library/system.directoryservices.propertycollection(v=vs.100).aspx

The below will enumerate all the current properties of the results of an LDAP search. You could adapt this to find all the properties that are currently used on the objects returned in the search result.

foreach (SearchResult item in searchResultCollection)
{
    foreach (string propKey in item.Properties.PropertyNames)
    {
        foreach (object property in item.Properties[propKey])
        {
            Console.WriteLine("{0} : {1}", propKey, property.ToString());
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM