是否可以在“按示例查询”中搜索 Guid?

发布于 2024-12-21 06:20:57 字数 675 浏览 0 评论 0原文

我需要查找给定 OU 中是否存在具有给定 Guid 的计算机。

为此,我更愿意编写一个示例查询搜索与 Guid 匹配的计算机。例如:

PrincipalContext context = new PrincipalContext(ContextType.Domain, domain, container);
ComputerPrincipal computer = new ComputerPrincipal(context);

computer.Guid = guidToMatch;

PrincipalSearcher searcher = new PrincipalSearcher(computer);
// Get the computer if it exists...

当然这不起作用,因为 ComputerPrincipal.Guid 字段是只读的。此外,ComputerPrincipal.AdvancedSearchFilter 不包含 Guid 字段。

这是可能的,还是有某种原因我不想这样做(比如更好的选择)?

I need to find whether a computer with a given Guid exists inside a given OU.

To do this, I'd prefer to write a Query By Example that searches for a computer matching a Guid. For example:

PrincipalContext context = new PrincipalContext(ContextType.Domain, domain, container);
ComputerPrincipal computer = new ComputerPrincipal(context);

computer.Guid = guidToMatch;

PrincipalSearcher searcher = new PrincipalSearcher(computer);
// Get the computer if it exists...

Of course this doesn't work, because the ComputerPrincipal.Guid field is read-only. Furthermore, the ComputerPrincipal.AdvancedSearchFilter does not contain a Guid field.

Is this possible, or is there some reason I wouldn't want to do this anyway (like a better alternative)?

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

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

发布评论

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

评论(2

⒈起吃苦の倖褔 2024-12-28 06:20:57

看起来处理这个问题的方法是使用 FindByIdentity()

PrincipalContext context = new PrincipalContext(ContextType.Domain, domain, container);
ComputerPrincipal computer = ComputerPrincipal.FindByIdentity(context, guidToMatch);

Looks like the way to handle this is to use FindByIdentity():

PrincipalContext context = new PrincipalContext(ContextType.Domain, domain, container);
ComputerPrincipal computer = ComputerPrincipal.FindByIdentity(context, guidToMatch);
写下不归期 2024-12-28 06:20:57

处理此问题的另一种方法是对表单进行基本搜索。这本质上允许您通过 objectGUID 搜索对象并返回匹配项,无论是计算机还是其他类型的对象。然后你可以检查该物体,看看它是否是你想要的......

Another way to handle this is to do a base search of the form . This will essentially allow you to search for the object by objectGUID and get back the match, be it a computer or some other type of object. You could then inspect the object and see if it is what you had in mind...

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