laviramesh
IS-IT--Management
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 = fs
penTextFile("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
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 = fs
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