是否可以在“按示例查询”中搜索 Guid?
我需要查找给定 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来处理这个问题的方法是使用
FindByIdentity()
:Looks like the way to handle this is to use
FindByIdentity()
:处理此问题的另一种方法是对表单进行基本搜索。这本质上允许您通过 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...