Home » ldap » Change Local Admin Password on All Computers in Your Domain

Here is an awesome script I found to change the admin password on all the computers in your domain.  It uses a simple visual basic object to search for all the computers in your domain’s Active Directory then loops through each computer and sets a new password for the Administrator account.

 

[sourcecode language=”vb”]
On Error Resume Next
rem http://blogs.technet.com/b/heyscriptingguy/archive/2007/07/03/how-can-i-change-the-local-administrator-password-on-all-my-computers.aspx
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.CommandText = _
"Select Name From ‘LDAP://DC=yourcompany,DC=com’ Where objectClass=’computer’"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
strComputer = objRecordSet.Fields("Name").Value

Set objUser = GetObject("WinNT://" & strComputer & "/Administrator")
objUser.SetPassword "mynewpassword!"

objRecordSet.MoveNext
Loop
[/sourcecode]

 

Leave a Reply

Your email address will not be published. Required fields are marked *