I use C # to search my local objectGuid computer by querying Active Directory. For this, I am currently using DirectorySearcher , passing it the (hard-coded) path as the search root, and then filtering by computer name:
string adRootPath = @"LDAP://OU=foo,DC=bar,DC=baz,DC=com"; DirectoryEntry adRoot = new DirectoryEntry(adRootPath); DirectorySearcher searcher = new DirectorySearcher(adRoot); searcher.Filter = @"(&(objectCategory=Computer)(CN=" + Environment.MachineName + "))";
I don't want to hardcode the search root and wondered if there is a better way. I thought about simply using the empty search root, but I was worried that computer names might not always be unique across domains.
Is there a better way?
source share