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 :-)
Error : SearchResultCollection resultCol = mySearcher.FindAll();
COMException was unhandled by user code
The servor is not operational
Could you provide any more background about this issue? it will be helpful for us to troubleshoot.
Regards,
Angie
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
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 :-)
All-Star
32817 Points
3815 Posts
Re: Query LDAP for computer names doesn't work
Feb 26, 2016 09:38 AM|Angie xu - MSFT|LINK
Hi,
Could you provide any more background about this issue? it will be helpful for us to troubleshoot.
Regards,
Angie
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.