Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I need to build a trees of domains in a forest. So far I have used the following code:
C#
using System.DirectoryServices.ActiveDirectory;

...

List<Domain> domains = new List<Domain>(); // flat list of domains
foreach (Domain dom in Forest.GetCurrentForest().Domains)
{
    try
    {
        domains.Add(dom);
        var de = dom.GetDirectoryEntry();
        // Here I have de.Guid and de.Parent.Guid, so using them I can build a tree
    }
    catch () {} // for simplicity left it blank.
}

The code works well. But when some of the domain becomes unavailable, the response (Domain.GetDirectoryEntry()) can take a while (15-20 sec.) before exception throwing. But using Active Directory Domains and Trusts, it is possible to retrieve all forest trees pretty fast with problem domains, so I suppose that there is some cache of domains somewhere.

Q:

If this cache is in the Global Catalog, I wonder - is it possible to have AD structure without GC?

And how can I perform a faster enumeration of forest domains, and build a tree structure?
Posted
Updated 5-Jun-14 18:49pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900