Const adOpenStatic = 3 Const adLockOptimistic = 3 Dim strComputername, strPassword Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset") Set WshShell = WScript.CreateObject("WScript.Shell") Set args = WScript.Arguments strComputername = args(0) objConnection.Open "Provider=SQLOLEDB;Data Source=SCCM01;" & "Trusted_Connection=Yes;Initial Catalog=MDT;" objRecordSet.Open "SELECT 'computername' FROM JLadmin", objConnection, adOpenStatic, adLockOptimistic objRecordSet.MoveFirst 'Check if exists set myrecordset = objconnection.execute("SELECT Computername FROM JLadmin WHERE Computername = '" & strcomputername & "'") If myRecordset.EOF Then call GeneratePW Call ChangePW call Create 'Wscript.Echo "Record cannot be found." Else 'strtest = myrecordset("Computername") 'wscript.echo strtest call GeneratePW Call ChangePW call Update End If Sub Update 'Update Existing 'Wscript.echo "Update" set myrecordset = objconnection.execute("Update JLadmin SET Localadminpw = '" & strPassword & "' WHERE Computername = '" & strcomputername & "'") End Sub Sub Create 'wscript.echo "Create" 'Create new record set myrecordset = objconnection.execute("Insert INTO JLadmin (Computername, LOcaladminpw) Values ('" & strcomputername & "', '" & strpassword &" ')") End Sub Sub ChangePW Set objUser = GetObject("WinNT://" & strcomputername & "/Administrator, user") 'wscript.echo "changepw" objUser.SetPassword strPassword objUser.SetInfo End Sub Sub GeneratePW 'wscript.echo "Generatepw" intUpperLimit = 10 intLowerLimit = 7 Randomize intCharacters = Int(((intUpperLimit - intLowerLimit + 1) * Rnd) _ + intUpperLimit) intUpperLimit = 122 intLowerLimit = 46 For i = 1 to intCharacters Randomize intASCIIValue = Int(((intUpperLimit - intLowerLimit + 1) * Rnd) _ + intLowerLimit) If intASCIIValue = "94" then intASCIIValue = "33" end if If intASCIIValue = "96" then intASCIIValue = "34" end if strPassword = strPassword & Chr(intASCIIValue) Next End Sub