如何使用C#来获得在Active Directory中的所有域的列表 [英] How to get list of all domains in Active Directory using C#

查看:128
本文介绍了如何使用C#来获得在Active Directory中的所有域的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以请帮我把所有在Active Directory的域。我已经试了很多次,但所有的程序都仅列出当前的工作域。

我怎样才能做到这一点?

解决方案

 域域= Domain.GetDomain(新DirectoryContext(DirectoryContextType.Domain,您的域,用户名,密码));

森林森林= domain.Forest;

DomainCollection域= forest.Domains;
 

上面使用System.DirectoryServices.ActiveDirectory命名空间。它会给你一个包含所有在同一林中的给定域的域的域集合。

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?

解决方案

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.

这篇关于如何使用C#来获得在Active Directory中的所有域的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆