Setting User Account Passwords

Microsoft® Windows® 2000 Scripting Guide

After creating a user account, you should set a password that a user will enter to log on to the network. If the password policies in the domain dictate that a password is required, you will have to set a password because Active Directory does not automatically add a password to a user account when it is created.

Table 7.3 shows the argument of the SetPassword method.

Table 7.3 Argument of the SetPassword Method










New password value

Scripting Steps

Listing 7.2 contains a script that sets a user account password to a specified value. To carry out this task, the script performs the following steps:

  1. Bind to the user account object by using the GetObject function and the LDAP provider.

  2. Use the SetPassword method to set the user accounts password to the specified value.

Listing 7.2 Setting a User Account Password


Set objUser = GetObject _
objUser.SetPassword "i5A2sj*!"

After the user account is enabled, a user can log on as MyerKen in the domain with the password i5A2sj*!. The password is case sensitive when the user logs on from a computer running a Windows NTbased operating system but is not case sensitive when the user logs on from computers running other Windows operating systems, such as Windows 98. For Windows NTbased computers, a password of PASSWORD is not the same as a password of password.


  • Listing 7.2 shows the basic script structure required to set a user account password. However, you can improve on this script by using the Arguments property of the Windows Script Host (WSH) WScript object to receive parameters, such as the user account name and the OU where the user account resides. For more information about using the Arguments property, see "WSH Primer" in this book.