Automate change of multiple local user passwords on a single server

Posted on 2009-05-21
Medium Priority
Last Modified: 2013-11-10
We recently setup approx. 70 local user accounts on a server for our vendors to access. All the users are part of a local group. As part of our company policy the passwords need to be changed every 60 days. We would like to create a script or batch file to change the passwords on each of these accounts. The passwords should be pulled from a pre-generated file, created by Quicky Password Generator, as each vendor will have a different password. I have attached an example of the generated file. Any help or direction is appreciated.
Question by:Gerald_Tipler
LVL 20

Expert Comment

ID: 24442067
You can do this from the command prompt. To change the password of a user from the command prompt, go to Run > cmd.  Command prompt will open. Use the following commands to change the password:
net user username password /domain

You can write a batch file that takes as input the contents of the generator file.
LVL 22

Expert Comment

ID: 24442416
The code to change a password is pretty easy:
Set objUser = GetObject("WinNT://server01/Pre2KNamer")

Probably the easiest way to change their passwords would be to use a "net localgroup vendorgroupname >vendornames.txt" to export the list of hte vendors you have to a txt file. Next, clean up the text file because net localgroup creates some extra info.  Lastly, use another piece of vbscript to read the vendor file and the password file and change passwords.

LVL 38

Accepted Solution

Shift-3 earned 2000 total points
ID: 24442493
Paste the script below into a text file with a .vbs extension.  Customize the value of the strComputer variable on line 7 with the target computer name.  Customize the value of the strGroup variable on line 8 with the name of the local group.  Customize the value of the strPwList variable with the location of the password list.

Running the script will reset the passwords of all users in the group and output the usernames with their new passwords to a comma-delimited text file.

Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
On Error Resume Next
strComputer = "server01"
strGroup = "vendors"
strPwList = "c:\files\qpwords.txt"
strReport = "report.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objPwList = objFSO.OpenTextFile(strPwList, ForReading, False, TriStateUseDefault)
Set objReport = objFSO.OpenTextFile(strReport, ForWriting, True)
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup)
For Each objUser in objGroup.Members
    strPw = objPwList.ReadLine
    objReport.WriteLine objUser.Name & "," & strPw

Open in new window


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Today, unlike web development, the mobile landscape is complex enough for a software engineer and Android is posing more challenging environment thanks to its fragmentation issues on hardware and software fronts.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Loops Section Overview

607 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