Subscribe to Windows IT Pro
January 03, 2001 12:00 AM

Practical Usage of ADSI: Password Management for Machine Accounts and Local Administrators

Windows IT Pro
InstantDoc ID #16292
Rating: (2)
Downloads
16292.zip

Active Directory Service Interfaces

Throughout the past 2 years, Windows Scripting Solutions (formerly Win32 Scripting Journal) has presented articles about how to use Active Directory Service Interfaces (ADSI) in scripts to manage most elements of Windows 2000 and Windows NT enterprise administration. With these basic elements mastered, you now have the foundation to use ADSI and your favorite scripting language to create robust administrative applications.

In this column, I'll show you how to build on the techniques you've learned (and show you some new ones) so that you can create scripts that solve particularly difficult problems administrators face regularly. This month, I show you how to use ADSI and VBScript to tackle two password-related tasks: finding and removing unused machine accounts in a domain and changing the local Administrator account password on workstations and member servers.

Finding and removing unused machine accounts. When it comes to namespace housekeeping, most enterprises do a great job keeping user accounts current and accurate because of the risks associated with failing to do so. However, the same can't always be said for machine accounts. Although these accounts don't pose any significant risk to an enterprise's security, keeping the SAM up-to-date is important. You can often decrease the amount of time it takes to run scripts by simply reducing the number of invalid machine accounts in the SAM, especially if those scripts use enumeration functions at the domain level.

Changing the local Administrator account passwords. The biggest problem with changing the local Administrator account password is the sheer number of machines on which you need to change it. Because this tedious task is time-consuming, often the same password that was assigned to the Administrator account when the machine was built remains for the life of that build. Worse yet, many enterprises use a single password for the Administrator account on all machines. This practice yields a tremendous security risk because someone just needs to compromise one machine's account database to obtain unauthorized, untraceable access to all workstations and member servers. In addition, regularly checking and changing passwords can flag instances in which central administrators unknowingly lose their access to a machine because someone modified the Administrators or Users group membership.

To solve both problems simultaneously, you can write a script that will

  • Enumerate all domains in an enterprise
  • Enumerate all machine accounts in each domain
  • Identify inactive machine accounts (i.e., accounts that have been off the network for the past 180 days)
  • Change the Administrator account password on each remaining machine to a random value
  • Report results back to a text file, ODBC data source, or Microsoft Excel workbook

Enumerating All Domains
To enumerate all domains in the enterprise, you bind to the ADSI service provider and step through the returned collection, as Listing 1 shows. When you run this code, it returns a list specifying all the domains in the WinNT: namespace. If you want to add to the enumeration's effectiveness, you can use additional For Each...Next statements within the enumeration to return a list of every computer in each domain, as the next section shows.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Mar 16, 2005

    I have one thind to say and it is a great software that fixed my problem. Keroon.

  • kukri
    8 years ago
    Aug 13, 2004

    I downloaded the scripts and used listing 4 to list systems. It ran once on my domain and then failed. It says "user could not be found". And references this line: "Set oComputerAccount=GetObject(oComputer.AdsPath & "$,user")"

    Any ideas what I am doing wrong?

  • Tommy E Burton
    8 years ago
    Feb 14, 2004

    I changed my password but now cannot remember it or the administrator password either. How can I get my password reset without losing any information on my machine. I am running Windows XP Professional.

  • Francois Greyling
    9 years ago
    Dec 19, 2003

    This is exactly what I am looking for. I have tried to download the Excel file from the Windows Scripting Solutions Web site, but it is no longer available. Where can I get it?



    Note from the Editors: To obtain the Excel file, click the 16292.zip link that appears under the Download the Code heading at the beginning of the article.

  • Jeff Fink
    9 years ago
    Dec 16, 2003

    Is the time frame for the "Inactive Accounts" Listing 4 wrong? If seconds are used to determine machine accounts older than 180 days, this condition should be 15552000 not 7776000. My calculations say that if seconds are used 7776000 comes out to 90 days not 180.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.