Active Directory/Search for a user: Difference between revisions
Content added Content deleted
(New page: ==VBScript== Creating the normal connection to AD Set objConn = CreateObject("ADODB.Connection") Set objCmd = CreateObject("ADODB.Command") objConn.Provider = "ADsDSOObject" objConn.Op...) |
mNo edit summary |
||
Line 28: | Line 28: | ||
[[Category:VBScript]] [[Category:Active Directory]] [[Category:Solutions by Programming Task]] [[Category:Programming |
[[Category:VBScript]] [[Category:Active Directory]] [[Category:Solutions by Programming Task]] [[Category:Programming Tasks]] |
Revision as of 21:50, 6 August 2008
VBScript
Creating the normal connection to AD
Set objConn = CreateObject("ADODB.Connection") Set objCmd = CreateObject("ADODB.Command") objConn.Provider = "ADsDSOObject" objConn.Open
The search string and execution of the string
strUsername = "TestUser" strQuery = "<LDAP://dc=skycityauckland,dc=sceg,dc=com>;"_ & "(&(objectclass=*)(samaccountname=" & strUsername & "));samaccountname,memberof;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