views:

3612

answers:

3

Can anyone please help me to get all the domains in Active Directory. I have tried many times, but all the programs are listing only the current working domain.

How can I do this?

+1  A: 

Using DirectorySearcher you can connect and read the structure of one Active Directory, including the structure (organization units, groups, users, computers, domain controllers). In order to connect to a different domain, you would need credentials of that other domain. We had problems in connecting to another domain from a machine that belongs to a different domain than the target one. I'm also curious if that's even possible.

Sergiu Damian
+5  A: 
Domain domain = Domain.GetDomain(new DirectoryContext(DirectoryContextType.Domain, "yourDomain", "username", "password"));

Forest forest = domain.Forest;

DomainCollection domains = forest.Domains;

The above uses the System.DirectoryServices.ActiveDirectory namespace. It'll give you a domain collection containing all the domains that are in the same forest as your given domain.

LeeMobile
A: 

I bookmarked this link the other day. It offers an approach to to doingthis using LDAP queries. Should be adaptable to ADSI.

http://itchanged.com/FindingAllDomainsInAnActiveDirectoryForest.html

Mike Beach