Saturday, October 3, 2009

Change Local Administrator Password In a Domain Envirement.

In resent i had a problem that changing the Local Administrator Password in all the PC that are connected to the domain.and i never liked that go to every PC and change the password.I found a VB script to do that with out any problems. and it works on windows 2008 DC.

01. Open the Notepad and copy and paste the following Script

' Change Local Administrator Password
' 23/09/2009
'...............................................................


On Error Resume Next

Dim fso, CLAPP
Set fso = CreateObject("Scripting.FileSystemObject")

'--------------------------------------------------------------------
' Change the location as You wish
' This will list of computers that has change the Local Admin Password.
'--------------------------------------------------------------------

Set CLAPP = fso.CreateTextFile("c:\Logs\Local administrator Paawords.txt", True)

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

' -------------------------------------------------
' Change the Domain Name To your domain name.
' DC=Domain name , DC=suffix (COM)
' -------------------------------------------------
objCommand.CommandText = _
"SELECT Name FROM 'LDAP://dc=Knights,dc=local' WHERE objectCategory='computer'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

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

'------------------------------------------------------------------------------------
'Change the names of the Machines that not need to Change the Administrator passwords
'------------------------------------------------------------------------------------
if Instr(1,strComputer, "srv01") Then objRecordSet.MoveNext
if Instr(1,strComputer, "srv02") Then objRecordSet.MoveNext
if Instr(1,strComputer, "DOMAINCONTROLLER3") Then objRecordSet.MoveNext
'-----------------------------------------------------------
' change the Password as you like
'-----------------------------------------------------------
strPassword = "P@ssword"


CLAPP.WriteLine(strComputer & " " & strPassword)
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator")
objUser.SetPassword strPassword

objRecordSet.MoveNext
Loop

CLAPP.Close

02.save this as CLAP.vbs
03.Run it as logon script Using GPO .If you don't know how to do that see the following article.
(http://www.petri.co.il/setting-up-logon-script-through-gpo-windows-server-2008.htm)
04.if you want know more about VB scripting go to http://computerperformance.co.uk/vbscript.

0 comments:

Post a Comment