This week I got a task to perform a LDAP query and fetch few user information. Challenge was to perform the fetch action not from our current domain but rather a different domain; that too not with FQDN but with IP. This was not too tricky as all I need to do was configure the DirectoryEntity first and then pass it to the usual DirectorySearcher which we use to perform LDAP.
Let me explain that in detail, step by step:
3> Initialize the DirectoryEntity object with the following:
4> Initialize the DirectorySearcher object with the DirectoryEntry.
This would do a DNS lookup to find a DC where the AD resides.
5> Now it’s time to set the filter properties of the DirectorySearcher with the LDAP query.
I’ll pass on the LDAP query to Configuration Manager AppSettings as the query will change from time-to-time.
6> Once everything is set, it’s time for the results. Results are captured using SearchResult with:
7> Build the code and .exe is ready to be executed in the server. 🙂
Hope this was helpful. Thank much! 🙂