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

时间:2011-12-15 22:37:12

标签: c# .net active-directory query-by-example

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

为此,我更愿意编写Query By Example来搜索与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字段。

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

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:0)

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