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

Quick help needed...binding to user in AD

Status
Not open for further replies.

keybrdcowboy

IS-IT--Management
Aug 31, 2004
96
US
Here's my code. For whatever reason, I cannot get it to bind to AD for the user specified in the array. Can anyone help me out? Thanks.


Code:
' Script used to change the login script for a selected group of users.  You must have the list of users in a text file named "usernames.txt" in order
' for this to work.  Edit the variable named strScriptPath (located at the beginning of the script) to change the value placed in the users' profile. 



Option Explicit
Dim fsoIn, inFile, fsoOut, outFile, arruserPath, strUserName, objUser, ErrorOccurred, strScriptPath, CrUser, strADConn
Dim objRootDSE, strADsPath, objRootDomain, strDomain, objIADS, ADS_SECURE_AUTHENTICATION

Const inFilename = "usernames.txt"
Const outFilename = "ChangeUserLoginScript.log"  
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

strDomain = "Lackland"
strScriptPath = "testingscript.bat"


' Open the input file
Set fsoIn = CreateObject("scripting.filesystemobject")
Set inFile = fsoIn.OpenTextFile(inFilename, ForReading, True)

' Open the log file (append mode) and timestamp the entry
Set fsoOut = CreateObject("scripting.filesystemobject")
Set outFile = fsoOut.OpenTextFile(outFilename, ForAppending, True)
outFile.writeline (Now & vbTab & "Starting script...")

While Not inFile.AtEndOfStream
	arrUserPath = Split(inFile.Readline, vbTab, -1, 1)
	' arrUserPath(0) contains the user names
	strUserName = arrUserPath(0)
        wscript.echo strUserName

        Set objIADS = GetObject("WinNT:").OpenDSObject("WinNT://lackland,mobleyj,J(^%^8101m" & ADS_SECURE_AUTHENTICATION)        
        CRuser = objIADS.GetObject("user", strUserName)
        
  
	If Err.Number <> 0 Then
		outFile.writeline Now & vbTab & "Error connecting to " & strUserName & " --- " & Err.Description
		Err.Clear
		ErrorOccurred = True
	Else
		CrUser.scriptPath = strScriptPath
		CrUser.SetInfo
		If Err.Number <> 0 Then
			outFile.writeline Now & vbTab & "Error setting login script path for " & strUserName  & " --- " & Err.Description
			Err.Clear
			ErrorOccurred = True
		Else
			outFile.writeline (Now & vbTab & "New Login script path set for " & strUserName)
		End If
	End If
Wend

' Clean up the environment
outFile.writeline (Now & vbTab & "Ending script...")
inFile.close
outFile.close

If ErrorOccurred Then
	msgbox "Script completed with errors.  Please check the log file."
Else
	msgBox "Script completed successfully."
End If

It is a little messy, as I have been trying many different things. Thanks.
 
Take a look at this FAQ: faq329-5688

I hope you find this post helpful.

Regards,

Mark
 
Well, I looked at that already, and couldn't see how to adapt that to what I am trying to do. Yours does the binding and searching all at one time right? I need to bind to the user, and then make changes to that user...
 
Have you tried this ?
[highlight]Set [/highlight]CRuser = objIADS.GetObject("user", strUserName)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
keybrdcowboy,

I'd create an array for your users and then use the function to get the ldap. Here is an overview of how the script would be setup.

For Each User in MyArray
objUser = GetLDAPfromUserName(User)
Code to Modify User
Next

Function GetLDAPfromUserName(strUser)
Return LDAP
End Function

I hope you find this post helpful.

Regards,

Mark
 
Well, I got it working, but not how I wanted it to. Thanks for all your guys' help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top