Solved

Script to change the local administrators password on 60 Servers

Posted on 2006-06-14
8
187 Views
Last Modified: 2010-04-13
Ok what I would like is a vbs script to read a text file containing a list of the servers, read a text file containing a list of passwords, for the script to take each server name connect to it and change the password to the one in the text file and then to connect to the next server in the list and to change the password to the one on the next line down on the password list.  On completion to report 60 successfull password changes without the need to reboot the server.  Is this possible?
The script will be run as a domain admin so will have sufficient privileges to make the change

Needed quite urgently hence the points, oh mixture of NT4, W2k & 2003
0
Comment
Question by:coch
  • 4
  • 3
8 Comments
 
LVL 32

Assisted Solution

by:rsivanandan
rsivanandan earned 100 total points
ID: 16904657
Very Simple for a single password;

Go to http://www.sysinternals.com/Utilities/PsPasswd.html and get the pspasswd utility.

Then just run it this way;

Make a text file, lets call it 'file' and put in your machine names one by one into it.  

pspasswd @file Administrator <newpassword>

Run it with domain administrator privilege and you are done. Just create a batch file and keep it for future.

Batch File:

pspasswd @file Administrator %1

Save the above into 'change.bat' and invoke it as 'change.bat <newpassword>'

For multiple passwords, you'll have to create a batch file to create a loop and read the password from the other file;



Cheers,
Rajesh
0
 

Author Comment

by:coch
ID: 16905612
Thanks, but I really want different passwords on each machine, so how would I create the loop?
0
 
LVL 1

Accepted Solution

by:
johnreck earned 400 total points
ID: 16906135
Dim fso
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set objArgs = WScript.Arguments.Unnamed
 
 InputFile = "C:\input.txt"
 MyDate = Replace(Date, "/", "-")
 OutputFile = "C:\output-" & mydate & ".txt"
 

         If fso.FileExists(InputFile) Then
             Set txtStreamIn = fso.OpenTextFile(InputFile)
             Set txtStreamOut = fso.OpenTextFile(OutputFile, 2, True)
             Do While Not (txtStreamIn.AtEndOfStream)
                 Dim s
                 Dim lst
                 s = txtStreamIn.ReadLine
                 lst = Split(s) ' returns an array
                 MsgBox lst(0)
              MsgBox lst(1)
                 strcomputer = lst(0)
                 password = lst(1)
                 'strComputer = txtStreamIn.ReadLine
                 chpw strComputer, password
             loop
         Else
             WScript.Echo "Input file doesnt exist."
             usage
         End if
 
 Sub printOut (data)
     WScript.Echo data
     txtStreamOut.writeline data
 End Sub 'printOut
 
 Sub chpw (computer,password)    
     Set objUser = GetObject("WinNT://" & computer & "/administrator, user")
     printOut "changing the password on " & computer & " to " & password & " successful"
     objUser.SetPassword password
     objUser.SetInfo
 End Sub 'chpw
 

Notes
the input.txt file each line should be
computername password

leave 1 space in between computername and password

Also objuser  change administrator to the local administrator account if it is not called administrator

also must be run by some one with admin rights.
0
 

Author Comment

by:coch
ID: 16909587
Thanks thats exactly what I wanted, however I have copied the above and it errored initially on the line Set objArgs = WScript.Arguments.Unnamed so I removed the word Unamed (?) and it ran and then it errored on the line usage so i removed this (?) and even though a file exists called input.txt at root of C: it says Input file doesn't exist?

Can you help?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Expert Comment

by:johnreck
ID: 16912488
delete this line totaly  Set objArgs = WScript.Arguments.Unnamed

also are you running XP?
 
also try a different file name
0
 

Author Comment

by:coch
ID: 16918188
deleted the line completely and used a different filr name data.txt and it ran a bit further, is shows the first server name and password in the message box then errors at line 36 character 6  the line Set objUser
0
 
LVL 1

Expert Comment

by:johnreck
ID: 16921268
do all the computers have the same local admin account name as administrator also the text file should be

computer password
computer password

with one space if it failes at Set objUser  it might be the admin account name is wrong.
0
 

Author Comment

by:coch
ID: 17041224
Thanks for your responses, however I am now going to use CUsrMgr part of Resource kit in Windows 2000 for this
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now