2011-12-15 52 views
1

我需要查找给定OU中是否存在给定Guid的计算机。是否可以在“按示例查询”中搜索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

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

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

另一种方式来处理,这是做一个基本搜索形式。这实际上允许你通过objectGUID搜索对象并获取匹配结果,无论是计算机还是其他类型的对象。然后你可以检查物体,看看它是不是你想到的......

相关问题