diff --git a/SharpLDAPSearch/Program.cs b/SharpLDAPSearch/Program.cs index 7db7b73..e1d3ba9 100644 --- a/SharpLDAPSearch/Program.cs +++ b/SharpLDAPSearch/Program.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.DirectoryServices; -using System.DirectoryServices.AccountManagement; using System.Linq; -using System.Text; namespace SharpLDAPSearch { @@ -35,8 +33,6 @@ static void Main(string[] args) Environment.Exit(0); } - //string[] searchProperties = { "name" }; - mySearcher.SizeLimit = int.MaxValue; mySearcher.PageSize = int.MaxValue; @@ -48,30 +44,19 @@ static void Main(string[] args) // Get the properties of the 'mySearchResult'. ResultPropertyCollection myResultPropColl; myResultPropColl = mySearchResult.Properties; - foreach (string myKey in myResultPropColl.PropertyNames) + + // return only specified fields + if (searchProperties.Count > 0) { - if (searchProperties.Count > 0) + foreach (string attr in searchProperties) { - if (searchProperties.Contains(myKey.ToString().ToLower())) - { - foreach (Object myCollection in myResultPropColl[myKey]) - { - Console.WriteLine("{0} - {1}", myKey, myCollection); - } - } - } - else - { - foreach (Object myCollection in myResultPropColl[myKey]) - { - Console.WriteLine("{0} - {1}", myKey, myCollection); - } + Console.WriteLine(mySearchResult.Properties[attr][0].ToString()); } } - /* - foreach (string myKey in myResultPropColl.PropertyNames) + // if no fields specified, return all + else { - if (searchProperties.Contains(myKey.ToString().ToLower())) + foreach (string myKey in myResultPropColl.PropertyNames) { foreach (Object myCollection in myResultPropColl[myKey]) { @@ -79,7 +64,7 @@ static void Main(string[] args) } } } - */ + mySearcher.Dispose(); entry.Dispose(); ; }