Active Directory/Search for a user: Difference between revisions

From Rosetta Code
Content added Content deleted
m (Moved to Enviro cat)
Line 1: Line 1:
{{task|Programming environment operations}}
{{task}}


=={{header|VBScript}}==
=={{header|VBScript}}==

Revision as of 00:17, 23 August 2008

Task
Active Directory/Search for a user
You are encouraged to solve this task according to the task description, using any language you may know.

VBScript

Make sure you Connect to Active Directory

The search string and execution of the string

strUsername = "TestUser"
strQuery = "<LDAP://dc=skycityauckland,dc=sceg,dc=com>;"_
 & "(&(objectclass=*)(samaccountname=" & strUsername & "));distinguishedname;subtree"
objCmd.ActiveConnection = objConn
objCmd.Properties("Page Size")=100
objCmd.CommandText = strQuery
Set objRS = objCmd.Execute

Doing something with a single result (this will output the returned users full DN)

If objRS.RecordCount = 1 Then
  WScript.Echo objRS.Fields("DistinguishedName")
End If

Doing something with multiple results (this will output each returned users full DN)

If objRS.RecordCount > 0 Then
  For Each objUser in ObjRS
    WScript.Echo objRS.Fields("DistinguishedName")
  Next
End If