Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


July 11, 2002

Real-World Scripting: Changing Passwords on Multiple Computers


RSS
View this exclusive article with VIP access -- click here to join | See More Windows NT 4.0 Articles Here | Reprints
Or sign up for our VIP Monthly Pass!
SideBar    Best Practices for Secure Administrator Accounts

Download the Code Here

Changing local Administrator account passwords on numerous servers and desktop PCs can be time-consuming. You can change passwords on a few servers manually, but if you're dealing with a lot of machines and long, complex passwords, changing passwords manually is burdensome. Furthermore, the possibility of someone incorrectly entering a password or putting a password on the wrong node is an ever-present risk. For security reasons, the somewhat-common practice of using the same password on several servers isn't ideal. To avoid these problems, you can buy third-party utilities to handle the task, or you can write a simple script that can do the job for free. For example, I wrote the script BulkChangePw.pl, which Listing 1, page 4, shows.

Using a Script to Create Passwords
Creating a lot of unique passwords can be challenging; people tend to think in terms of words or phrases, which often results in passwords that intruders can easily crack. (For some best practices to help you protect your Administrator accounts, see the Web sidebar "Best Practices for Secure Administrator Accounts," http://www.winscriptingsolutions.com, InstantDoc ID 25721.) The Roth Consulting Web site contains some excellent scripts. I used George Shaffer's Password.pl script (http://www.roth.net/perl/scripts/scripts.asp?password.pl) to generate strong, unique passwords. Password.pl includes configuration options that let you specify the number and length of passwords you need to generate. Because BulkChangePw.pl uses a Comma Separated Value (CSV) input file, be sure that you configure Password.pl to remove the comma (,) from the list of characters the script can use to create passwords. To fine-tune Password.pl's output to meet your requirements, install Perl, then download the script and run it from the command prompt. I used the command shell's quick-edit feature to copy a list of passwords into a Microsoft Excel spreadsheet.

Armed with an unlimited pool of unique passwords, you're ready to start building a CSV file to use as input for BulkChangePw.pl. For a change-password run, your CSV file should include a list of machine names in the first column, the renamed Administrator account names in the second column, the current machine passwords in the third column, and the new passwords that Password.pl generated in the fourth column. Each time you need to perform a new password-change run, move the new passwords from the previous run into the current-passwords column and insert another column of new passwords.

Retain a list of old passwords from the last several changes just in case a server is left off the network or otherwise neglected on earlier password-change runs. After you compile the list, save the file as a CSV file. Your file contents should look similar to the sample file contents that Figure 1 shows.

BulkChangePw.pl will parse the lines of the CSV file, use the file's information to change the passwords, and log the results. If you aren't familiar with Perl, BulkChangePw.pl can introduce you to Perl's powerful systems administration operations. The core code that changes the passwords uses the Win32::NetAdmin Perl module. (A Perl module is simply a utility that performs a specific function, similar to the way a resource kit tool performs a certain function.)

Code that runs an operation on several machines typically has three sections. The first section finds the list of machines on which the task will be performed. This list might come from an input file or another command. As callout A in Listing 1 shows, BulkChangePw.pl uses an input file (i.e., the CSV file) to obtain the server, account, and password information. The second section performs the task on each specified machine. As callout B shows, BulkChangePw.pl attempts to change the password on each machine. The third section reports the operation's success. The results might appear on screen, in an output file, or both. Displaying the results on screen gives the script operator feedback on a script run that's in progress and can reduce the possibility of someone accidentally closing a command-shell window and canceling a script run that's in progress. Logging results in an output file is beneficial when you need to examine the results closely or keep a record of the results. As callout C shows, I had BulkChangePw.pl log the results in addition to displaying them on screen. Using the log, I can examine individual password-change failures to determine whether the machine name was incorrect, the node was turned off, the account name was incorrect, or the old password was incorrect.

Making the Script Work
I wrote BulkChangePw.pl for changing passwords on Windows 2000 and Windows NT 4.0 servers and workstations. To get the script to work in your environment, follow these steps:

  1. Install Perl and the Win32::NetAdmin Perl module on the administrative PC or server on which you plan to run BulkChangePw.pl. You can obtain Perl from the ActiveState Web site (http://aspn.activestate.com//ASPN/Reference/Products/ActivePerl/faq/ActivePerl-faq2.html). Use the Perl Package Manager (PPM) to install the Win32::NetAdmin module. (The ActiveState Web site includes an explanation of how to use PPM.)
  2. Download BulkChangePw.pl from the Code Library on the Windows Scripting Solutions Web site (http://www.winscriptingsolutions.com).
  3. Create the CSV input file.
  4. Configure the location of the input and output files at the top of the script.
  5. Run the script in a small test environment on a few machines, then use the new passwords to log on to the machines locally to confirm that the script worked correctly.

In a production-server environment, administrators should test the local administration logon for each server after a password change. This task takes only a minute, but it can prevent major problems if the server's network connectivity breaks and you must log on locally. Determine whether this extra step is advisable in your environment.

End of Article



Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...

WinInfo Short Takes: Week of July 21, 2008

An often irreverent look at some of the week's other news, including an iPhone 3G defeat, 180 million copies of Windows Vista in the wild, Microsoft earnings some more Yahoo silliness, Wii vs. Xbox 360, EU vs. Intel, AMD ousts its CEO, and so much more ...

What service packs and fixes are available?

...


Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

Shortcut Guide to SQL Server Infrastructure Optimization
With right tools and techniques, you can have a top-performing SQL Server infrastructure without having to cram your data centers so that they're overflowing. Download this eBook to learn how.

WinConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

Become a fan of Windows IT Pro on Facebook!
Join us on Facebook and be a fan of Windows IT Pro!

Continuous Data Protection and Recovery for Exchange
Read this white paper to learn about Continuous Data Protection (CDP), Exchange 2007's local continuous replication and cluster continuous replication features.

Rev Up Your IT Know-How with Our Recharged Magazine!
The improved Windows IT Pro provides trusted IT content with an enhanced new look and functionality! Get comprehensive coverage of industry topics, expert advice, and real-world solutions—PLUS access to over 10,000 articles online. Order today!

Tips to Managing Messaging
Discover three fundamental mail and messaging management services - security, availability and control services - and how you can implement them in a Microsoft-centric mail and messaging environment.

Get It All with Windows IT Pro VIP
Stock your IT toolbox with every solution ever printed in Windows IT Pro and SQL Server Magazine plus bonus Web-exclusive content on hot topics. Subscribe to receive the VIP CD and a subscription to your choice of Windows IT Pro or SQL Server Magazine!



Drag & Drop Data Mapping Tool
Try this award-winning data mapping, & transformation tool that supports multiple databases, flat files, Web services, EDI, Excel 2007, & more! Free trial for 30 days!

Overcome bloated Windows file systems
Crossroads FMA delivers powerful yet inexpensive data migration

Bandwidth Monitoring Tool from SolarWinds
Identify largest bandwidth users in seconds. Get the free download now.

Speed Deployment of Vista and Microsoft Office
Read this white paper to learn how you can maximize your Vista and Office investments while lowering costs and increasing efficiency.

Integrated Virtualization Done Right
Download this white paper on server virtualization to begin improving resource utilization and lowering operating costs.

Order Your Fundamentals CD Today!
Gain an introduction to Exchange, learn server security requirements, and understand how unified communications can play a role in your messaging strategies with this free Exchange CD.

KVM over IP Solutions
Learn about a KVM over IP solution that is specifically designed to meet the needs of the distributed IT environment.
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound
IT Library Technical Resources Directory Connected Home Windows Excavator SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing