Created
October 17, 2013 09:09
-
-
Save rcknight/7021669 to your computer and use it in GitHub Desktop.
Query all active ad users who are real people (has a job title)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var context = new PrincipalContext(ContextType.Domain, "PHARMAXO.local", "OU=Corsham,dc=pharmaxo,dc=local")) | |
{ | |
var qbeUser = new UserPrincipal(context) { Enabled = true }; | |
using (var searcher = new PrincipalSearcher(qbeUser)) | |
{ | |
var results = searcher.FindAll().Select(r => r.GetUnderlyingObject() as DirectoryEntry); | |
var names = results.Where(r => r.Properties["title"].Value != null && ((string)r.Properties["title"].Value) != "") | |
.Select(r => String.Format("{0} {1}", r.Properties["givenName"].Value, r.Properties["sn"].Value)) | |
.OrderBy(r => r); | |
foreach(var name in names) | |
Console.WriteLine (name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment