Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Faster way to verify if a user account exists in AD?

Status
Not open for further replies.

cerruti1881

Technical User
Nov 8, 2012
10
AU
I need to verify if a user account entered exists in AD.
One way is to go through the entire AD to find a match, which may be slow if there are 100 thousands of objects.
Is there a faster of doing this? If yes, please share your idea and codes.
 
assuming your using the username.

Code:
Const ADS_SCOPE_SUBTREE = 2
strUsername = "aUsername"
strDomain = "dc=domain,dc=com"

set objConnection = CreateObject("ADODB.Connection")
set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"
objConnection.Open("Active Directory Provider")
objCommand.ActiveConnection = objConnection


objCommand.CommandText = "SELECT * FROM 'LDAP://" & strDomain & "' WHERE samAccountName = '" & strUsername & "'"
objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE

set objRecordSet = objCommand.Execute

if (objRecordSet.RecordCount = 0) then
	msgbox strUsername & " was not found"
else
	msgbox strUsername & " was found"
end if

-Geates

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top