Currently my code is:
using (var context = new PrincipalContext(ContextType.Domain, adDomain))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (Principal result in searcher.FindAll())
{
DirectoryEntry entry = result.GetUnderlyingObject() as DirectoryEntry;
if (entry.Properties["Company"].Value?.ToString() == "My Company")
{
// do some stuff
}
}
}
}
I was just wondering if it would be possible to do a LINQ statement instead of the if
statement to only get entries I am interested in.
Something like this:
foreach (var entry in searcher.FindAll()
.Where(x => x.GetUnderlyingObject<DirectoryEntries>()
.Properties["Company"].Value?.ToString() == "MY Company"))
{
// do some stuff
}