Last post Aug 07, 2014 05:37 AM by smirnov
Aug 06, 2014 11:34 AM|kouts1|LINK
I need to search for a user attribute and see if it exists using vb.net. For example, I need to see if the specified "employeeID" exists in AD w/o specifying SAMAccountName.
I have tried this, but not working:
Private Function IsExistInAD(empID As String) As Boolean
Dim search As New DirectorySearcher()
search.Filter = "(&(objectclass=user)(objectcategory=person))"
Dim result As SearchResult = search.FindOne()
If result Is Nothing Then
Aug 07, 2014 05:37 AM|smirnov|LINK
You might need to set location (or even authentication) for your LDAP query
Dim deGlobal As DirectoryEntry = New DirectoryEntry(ADPath, ADUser, ADPassword)
Dim searcher As DirectorySearcher = New DirectorySearcher(deGlobal)
Dim searcher As New DirectorySearcher()
searcher.SearchBase = ADPath
where ADPath is your location, e.g. LDAP://dc=dev,dc=company,dc=net
Query might be case-senstive, e.g. try "objectClass" and "objectCategory"
I always recommend to test queries in some tools like
LDAP Browser where you can check both LDAP path and queries and also see exactly how your AD has been built.