Get fully-qualified name of an OU
I have a code to get the list of OUs within a domain.
Now this just lists all the OUs and does not give any way to distinguish between an OU and a sub OU.
DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=organizationalUnit)");
foreach (SearchResult temp in mySearcher.FindAll())
{
OU_DownList.Items.Add(temp.Properties["name"][0].ToString());
}
Is there a way i can get the fully qualified name of an OU?
Something like this for a sub OU:
CN=Computer1,OU=Department 101,OU=Business 开发者_JAVA百科Unit #1,DC=us,DC=xyz,DC=com
Any help is appreciated... thanks
temp.Path
should get you the distinguishedName of each OU.
Use the property Path
from SearchResult
, as in temp.Path
, see link.
The Path property uniquely identifies this entry in the Active Directory hierarchy. The entry can always be retrieved using this path.
You can enumerate all the available properties with the following source code:
foreach(string propKey in temp.Properties.PropertyNames)
{
// Display each of the values for the property identified by
// the property name.
foreach (object property in temp.Properties[propKey])
{
Console.WriteLine("{0}:{1}", propKey, property.ToString());
}
}
精彩评论