[英]How can I query Active Directory Sites and Services in c#?
I don't know if I'm using the wrong search terms, but I can't find a decent example of this anywhere. 我不知道我是否使用了错误的搜索词,但是在任何地方都找不到合适的示例。
I'd like to query a specific AD site and return the computer names inside of it in c#. 我想查询一个特定的AD网站,并用c#返回其中的计算机名称。
I've tried this without luck 我没有运气尝试过
ActiveDirectorySiteCollection coll = new ActiveDirectorySiteCollection("ad site name");
And visual studio tells me it doesn't take a constructor with a single argument? 而且Visual Studio告诉我,构造函数不带单个参数吗?
You can use ActiveDirectorySite.FindByName
to find a specific site, then look at the Servers
property. 您可以使用
ActiveDirectorySite.FindByName
查找特定站点,然后查看Servers
属性。 For example: 例如:
var context = new DirectoryContext(DirectoryContextType.Forest);
var site = ActiveDirectorySite.FindByName(context, "SiteName");
foreach (DirectoryServer server in site.Servers) {
Console.WriteLine(server.Name);
}
If you don't know the name of the site, you can look up all the sites in your forest like this: 如果您不知道站点的名称,则可以像这样查找林中的所有站点:
var forest = Forest.GetCurrentForest();
foreach (ActiveDirectorySite site in forest.Sites) {
Console.WriteLine(site.Name);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.