Solved

Script to change the local administrators password on 60 Servers

Posted on 2006-06-14
8
190 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Corrupted W2K  serverregistry 2 150
Video card with drivers for Windows 2000 8 144
Running Baan iV on VMware 3 119
how to run this deletion request 4 12
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…
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

26 Experts available now in Live!

Get 1:1 Help Now