搜索Active Directory中的OU使用部分路径OU

编程入门 行业动态 更新时间:2024-10-28 06:27:55
本文介绍了搜索Active Directory中的OU使用部分路径OU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法在公元查询语法,通过搜索它的部分路径找到一个OU的完整路径?

Is there a way in AD Query syntax, to find an OU's full path by searching on its partial path?

例如,全路径,以我的OU是:

For example, the full path to my OU is:

OU=Clerks,OU=OfficeA,OU=Administration,DC=domain,DC=local

现在,我想通过使用部分路径,试图寻找并找到该对象:

Now, I'd like to try and search and find that object by using the partial path:

OU=Clerks,OU=OfficeA

我希望能够搜索是这样的:

I'd like to be able to search something like:

(&(objectCategory=organizationalUnit)(path=Clerks/OfficeA*))

我找不到如何完成这样的事情任何语法的例子。一个程序我开发需要,我得到的路径有很多OU在最后两个级别的OU的哪都有一个共同的结构,但它们可以嵌套在域中的任何给定的深度,否则。如果我能以某种方式寻找这样的,它会很容易获得通过的最后两个OU嵌套层次只是搜索的完整路径。

I can't find any syntax examples of how to accomplish something like this. A program I'm developing requires that I get the paths to a lot of OU's which all have a common structure in the last two levels of OU's, however they can be nested at any given depth in the domain otherwise. If I can search somehow like this, it would be easy to get the full path just searching by the last two OU nested levels.

推荐答案

您想要做的事情存在于纯粹的LDAP实现它的一个功能叫做 ExtensibleMatch 至极,似乎在的这个wiki文章。您还发现了一些有益的例子这里。

The thing you want to do exists on pure LDAP implementation it's a feature called ExtensibleMatch wich seems to be correctly explained in this wiki article . You will also found something helpfull examples here.

但它不是present在活动目录

But it's not present in Active-Directory

因此​​,这里是writen在C#中的利用父的方法的propertie一个的DirectoryEntry 。

So here is a method writen in C# that exploit the Parent propertie of a DirectoryEntry.

static List<DirectoryEntry> OuInTheFormOf(DirectoryEntry deBase, string ou1, string ou2) { List<DirectoryEntry> deList = null; /* Directory Search */ DirectorySearcher dsLookFor = new DirectorySearcher(deBase); dsLookFor.Filter = ou1; dsLookFor.SearchScope = SearchScope.Subtree; dsLookFor.PropertiesToLoad.Add("ou"); SearchResultCollection srcOUs = dsLookFor.FindAll(); if (srcOUs.Count != 0) { deList = new List<DirectoryEntry>(); foreach (SearchResult srOU in srcOUs) { DirectoryEntry deOU = srOU.GetDirectoryEntry(); if (deOU.Parent.Name.ToUpper() == ou2.ToUpper()) deList.Add(deOU); } } return deList; }

下面是用法:

/* Connection to Active Directory */ DirectoryEntry deBase = new DirectoryEntry("LDAP://WM2008R2ENT:389/dc=dom,dc=fr"); List<DirectoryEntry> l = OuInTheFormOf(deBase, "ou=Clerks", "ou=OfficeA"); foreach (DirectoryEntry deTmp in l) { Console.WriteLine(deTmp.Properties["distinguishedName"].Value); }

更多推荐

搜索Active Directory中的OU使用部分路径OU

本文发布于:2023-11-09 03:21:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571258.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   Active   Directory   OU

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!