using System; using System.DirectoryServices; using System.DirectoryServices.AccountManagement; namespace new_ad_exmaple { class Program { static void Main(string[] args) { try { PrincipalContext AD = new PrincipalContext(ContextType.Domain, "leeds-art.ac.uk"); UserPrincipal u = new UserPrincipal(AD); PrincipalSearcher search = new PrincipalSearcher(u); foreach (UserPrincipal result in search.FindAll()) { if (result.VoiceTelephoneNumber != null) { DirectoryEntry lowerLdap = (DirectoryEntry)result.GetUnderlyingObject(); Console.WriteLine("{0,30} {1} {2}", result.DisplayName, result.VoiceTelephoneNumber, lowerLdap.Properties["postofficebox"][0].ToString()); } } search.Dispose(); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } } } }