keybrdcowboy
IS-IT--Management
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.
It is a little messy, as I have been trying many different things. 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.