Solved

Script to change the local administrators password on 60 Servers

Posted on 2006-06-14
8
191 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

15 Experts available now in Live!

Get 1:1 Help Now