Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset or synchronize local admin password on workstations or servers

Scripting for the Enterprise

Reset or synchronize local admin password on workstations or servers

by  markdmac  Posted    (Edited  )
Through attrition, local admin passwords on domain computers tend to get out of sync. The below script will read a text file of domain computer names and syncronize the admin password on each listed machine. The script generates reports of the success and failures.

Like many of my scripts, this one uses a WSLIST.TXT file. You can easily generate that file using the script I provide in another of my FAQs faq329-4871.

Code:
Option Explicit[green]
'==========================================================================
'
' NAME: resetAdminPasswordsonPC.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE  : 4/21/2004
' COPYRIGHT (C) 2004, All Rights Reserved
'
' COMMENT: Resets the local admin password on domain computers.
'          Requires a list of workstation names called wslist.txt.
' MODIFICATIONS:   
'   7/9/2006- Added event log code
'
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
'==========================================================================[/green]
 
On Error Resume Next
Const EVENT_SUCCESS = 0 
Dim WSHShell, oFSO, oFailureReport, oSuccessReport, oTextStream, oAdminID, RemotePC, strComputerName
Dim adminPassword

Set WSHShell = CreateObject("Wscript.Shell") 
Set oFSO=CreateObject("Scripting.FileSystemObject")
 
If Not oFSO.FolderExists("c:\scripts\lists") Then
 oFSO.CreateFolder("c:\scripts")
 oFSO.CreateFolder("c:\scripts\lists")
End If 
 
If oFSO.FileExists("c:\scripts\lists\failed.txt") Then
   oFSO.DeleteFile("c:\scripts\lists\failed.txt")
End If 
 
If oFSO.FileExists("c:\scripts\lists\success.txt") Then
   oFSO.DeleteFile("c:\scripts\lists\success.txt")
End If 
 

set oFailureReport=oFSO.createtextfile("c:\scripts\lists\failed.txt")
set oSuccessReport=oFSO.createtextfile("c:\scripts\lists\success.txt")
 
 
 
[green]
'open the data file[/green]
Set oTextStream = oFSO.OpenTextFile("wslist.txt")

If Err Then
	MsgBox vbTab & vbTab & "WSLIST.TXT Source File Required" & vbCrLf & "Create the file, place in the same directory as this script and try again."
	WScript.Quit
End If
[green]
'make an array from the data file[/green]
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
[green]'close the data file[/green]
oTextStream.Close
 

For Each strComputername In RemotePC
[green]    'Goto the local Admin account of the machine[/green]
    set oAdminID = GetObject("WinNT://" & strComputername & "/administrator,user")[green]
      'Check for error and record in case of failed attempt
[/green]      If Err Then
        ReportError()
        Err.Clear
      Else
          adminPassword = [red]"putnewpasswordhere"[/red]
          oAdminID.SetPassword adminPassword
          oAdminID.SetInfo
          oSuccessReport.WriteLine strComputername & " Admin Password was reset."
      End If
	WSHShell.LogEvent EVENT_SUCCESS, _
    "Admin password reset by a script from The Spider's Parlor. http://www.thespidersparlor.com/vbscript", "\\" & strComputername
Next
[green] 
'Close all open files[/green]
oFailureReport.close
oSuccessReport.close
[green] 
'Let us know its finished[/green]
msgbox "Done"
 
set oFSO = nothing
set oAdminID = Nothing
set oTextStream = nothing
set oSuccessReport = nothing
set oFailureReport = nothing
 
Sub ReportError()
    oFailureReport.WriteLine strComputername & " could not be reset. Check that it is powered on." & Err.Number
End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top