如何在 C# 中枚举每个林的 Active Directory 域?

发布于 2024-09-26 11:49:39 字数 444 浏览 0 评论 0原文

如果正在运行的计算机是林的一部分,则此代码将枚举 Active Directory 域。

public static ArrayList EnumerateDomains()
{
    ArrayList alDomains = new ArrayList();
    Forest currentForest = Forest.GetCurrentForest();
    DomainCollection myDomains = currentForest.Domains;

    foreach (Domain objDomain in myDomains)
    {
        alDomains.Add(objDomain.Name);
    }
    return alDomains;
}

是否可以枚举属于其他森林一部分的域?

森林和全局目录有什么区别?

This code enumerate Active Directory domains, if the mahine on which is running is part of the forest.

public static ArrayList EnumerateDomains()
{
    ArrayList alDomains = new ArrayList();
    Forest currentForest = Forest.GetCurrentForest();
    DomainCollection myDomains = currentForest.Domains;

    foreach (Domain objDomain in myDomains)
    {
        alDomains.Add(objDomain.Name);
    }
    return alDomains;
}

Is it posible to enumerate domains which are part of some other forest ?

What is the difference between forest and global catalog ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逐鹿 2024-10-03 11:49:39

如果您将 currentForest 的设置替换为对 Forest.GetForest 标识您希望枚举其域的林。

DirectoryContext context = new DirectoryContext(DirectoryContextType.Forest,
    "dns-name-of-target-forest");
Forest currentForest = Forest.GetForest(context);

如果您没有权限,但知道有人有权限,可以使用 DirectoryContext 构造函数重写 允许您指定备用名称和密码。

此处详细介绍了全局编录与林的关系。简而言之,森林是对 AD 对象进行分组的 Active Directory (AD) 抽象。全局编录(如果林有的话)是一种分布式数据存储库,需要它才能在该林上执行某些类型的操作。

The logic above should work (provided permissions are OK) if you replace the setting of currentForest with a call to Forest.GetForest that identifies the forest whose domains you wish to enumerate.

DirectoryContext context = new DirectoryContext(DirectoryContextType.Forest,
    "dns-name-of-target-forest");
Forest currentForest = Forest.GetForest(context);

If you don't have permission but do know someone who does, there are DirectoryContext constructor overrides that allow you to specify an alternate name and password.

The relationship of global catalog to forest is detailed here. In short, a forest is an Active Directory (AD) abstraction for grouping of AD objects. A global catalog (if the forest has one) is a distributed data repository that is required in order for certain types of operations to be done on that forest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文