简体   繁体   English

使用C#获取位于AD OU中的所有服务器

[英]Get all servers located in OU in AD with C#

I am trying to collect all the server objects in a OU in AD with C#, but I am not successful. 我正在尝试使用C#在AD的OU中收集所有服务器对象,但是我不成功。

I try to access the OU like this: 我尝试像这样访问OU:

var context = new PrincipalContext(ContextType.Domain, "NO", "OU=Servers");

Is this correct? 这个对吗?

And I try to group with this: 我尝试与此分组:

var groupPrincipal = new GroupPrincipal(context, "*");

But that throws an error. 但这引发了错误。

What is the right way to go about to access the objects in a OU? 在OU中访问对象的正确方法是什么?

I found the problem. 我发现了问题。 The Servers OU did not have any groups inside it. 服务器OU内没有任何组。 Only more OU's based on Windows Server version. 仅基于Windows Server版本的更多OU。 So to access the servers inside the OU's I had to reference nested OU like this: OU=2012, OU=Servers. 因此,要访问OU内部的服务器,我必须像这样引用嵌套的OU:OU = 2012,OU =服务器。

I also had to drop GroupPrincipal. 我还不得不放弃GroupPrincipal。

To access the servers I used the code from "Enumerate Objects in a OU" at http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#19 要访问服务器,我使用了http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#19中 “枚举OU中的对象”中的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM