Question

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)?

Was it helpful?

Solution

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);

OTHER TIPS

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top