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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching Active Directory

Status
Not open for further replies.

laviramesh

IS-IT--Management
Nov 8, 2004
3
US
Hi

I m trying to modify the user properties in Active directory. I have taken a script sample from Microsoft and expanded it. In the Microsoft sample a username must be specified, whereas I am trying to read a user name from a text file. The script is not substituting the username variable in the selcet statement. I tried single quotes around the variable also.

Any ideas will be greatly appreciated.

Option Explicit

Const ForReading = 1


Dim objconnection,objcommand,objRecordset,fso, InputFile,struser,strDN,objuser


Set fso = CreateObject("Scripting.FileSystemObject")

Set InputFile = fso_OpenTextFile("c:\users.txt", ForReading, False)

Do until InputFile.AtEndOfStream

Set struser = InputFile.ReadLine
wscript.echo struser


Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT distinguishedName FROM 'LDAP://dc=hcggte,dc=frte,dc=co,dc=hennepin,dc=mn,dc=us' WHERE objectCategory='user'" & _
"AND SAMAccountName= & struser"


Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName").Value
objRecordSet.MoveNext
Loop

Set objUser = GetObject("LDAP://" & strDN)
Wscript.Echo objUser.Name

loop

InputFile.Close


 
[1] You should post the question to vbs forum
It may not completely off in vb forum, but it might draw resentment.

[2] You should move const declaration outside of the loop. It is a runtime error to "redeclare" constant.

[3] Move all the setting up of ado objects outside of the loop before setting up commandtext using struser.

[4] Take out the set keyword reading from readline, it is a runtime error.
[tt] [red]'[/red]Set struser = InputFile.ReadLine
struser = InputFile.ReadLine
[/tt]
The rest I wouldn't care unless those are corrected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top