?
Solved

Script to change the local administrators password on 60 Servers

Posted on 2006-06-14
8
Medium Priority
?
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 32

Assisted Solution

by:rsivanandan
rsivanandan earned 400 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 1600 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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

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…
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

765 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