Re: Remotely Reset the local administrator password



This should do the trick. Just change the path to where you want the
log, the domain info, and the new password. It can take a while to
complete. I ran it against the 1500 in my domain, and it took almost 2
hours.

-----------------------------------------------------------

Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set TextFile = FSO.OpenTextFile("C:\scripts\AutoChangePW.log", 2, True)


On Error Resume Next

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 Name FROM 'LDAP://dc=scripting,dc=microsoft,dc=com' WHERE
objectCategory='computer'"
Set objRecordSet = objCommand.Execute

' Get new password
newPassword="PassWord"


' Open the log file
Set oOutFile = oFSO.OpenTextFile(outFilename, ForAppending, True)


Do Until objRecordSet.EOF
strComputer = objRecordSet.Fields("Name").Value
Set objUser = GetObject("WinNT://" & strComputer & "/administrator,
user")
If Err.Number <> 0 Then
oOutFile.writeline Now & vbTab & "Error connecting to " & strComputer
& " --- " & Err.Description
Err.Clear
ErrorOccurred = True
Else
' Set the password for the account
objUser.SetPassword newPassword
objUser.SetInfo
If Err.Number <> 0 Then
oOutFile.writeline Now & vbTab & "Error setting password for " &
strComputer & _
"\pcadmin" & " --- " & Err.Description
Err.Clear
ErrorOccurred = True
Else
oOutFile.writeline (Now & vbTab & "Password set for " & strComputer
& "\administrator")
End If
End If
objRecordSet.MoveNext
Loop

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

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

Set TextFile = Nothing
Set WshNetwork = Nothing
Set FSO = Nothing

.


Loading