public static List<string> GetComputers()
{
List<string> ComputerNames = new List<string>();
DirectoryEntry entry = new DirectoryEntry("MyLDAP"); //I can t put my real LDAP online so I put MyLDAP
//Debug.WriteLine(entry.count());
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(objectCategory=computer)";
mySearcher.SizeLimit = int.MaxValue;
mySearcher.PageSize = int.MaxValue;
mySearcher.PropertiesToLoad.Add("name");
SearchResultCollection resultCol = mySearcher.FindAll();
SearchResult result;
for (int counter = 0; counter < resultCol.Count; counter++)
{
result = resultCol[counter];
string ComputerName = result.GetDirectoryEntry().Name;
ComputerNames.Add(ComputerName);
}
//mySearcher.Dispose();
//entry.Dispose();
return ComputerNames;
}
And I have this error at this line :
Error : SearchResultCollection resultCol = mySearcher.FindAll();
COMException was unhandled by user code
The servor is not operational
Do you know where the problem comes from ? Is it about my LDAP that is wrong, or my filter ...
I need to get all the computer name in a list.
Thanks for your help :-)
None
0 Points
5 Posts
Query LDAP for computer names doesn't work
Feb 18, 2016 02:12 PM|Eliot777|LINK
public static List<string> GetComputers()
{
List<string> ComputerNames = new List<string>();
DirectoryEntry entry = new DirectoryEntry("MyLDAP"); //I can t put my real LDAP online so I put MyLDAP
//Debug.WriteLine(entry.count());
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(objectCategory=computer)";
mySearcher.SizeLimit = int.MaxValue;
mySearcher.PageSize = int.MaxValue;
mySearcher.PropertiesToLoad.Add("name");
SearchResultCollection resultCol = mySearcher.FindAll();
SearchResult result;
for (int counter = 0; counter < resultCol.Count; counter++)
{
result = resultCol[counter];
string ComputerName = result.GetDirectoryEntry().Name;
ComputerNames.Add(ComputerName);
}
//mySearcher.Dispose();
//entry.Dispose();
return ComputerNames;
}
And I have this error at this line :
Error : SearchResultCollection resultCol = mySearcher.FindAll();
COMException was unhandled by user code
The servor is not operational
Do you know where the problem comes from ? Is it about my LDAP that is wrong, or my filter ...
I need to get all the computer name in a list.
Thanks for your help :-)