我需要查看给定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
字段。
这是可能的,还是有某种原因我不想这样做(比如更好的选择)?
答案 0 :(得分:3)
看起来处理此问题的方法是使用FindByIdentity()
:
PrincipalContext context = new PrincipalContext(ContextType.Domain, domain, container);
ComputerPrincipal computer = ComputerPrincipal.FindByIdentity(context, guidToMatch);
答案 1 :(得分:0)
处理此问题的另一种方法是对表单进行基本搜索。这基本上允许您通过objectGUID搜索对象并返回匹配,无论是计算机还是其他类型的对象。然后你可以检查对象,看看它是不是你想到的......