Introduction to Setting Passwords
Note 1: I have a new VBScript to Set Passwords
Note 2: I have a new script to force users to change password at next logon
When it comes to creating users, VBScript has a great advantage over CSVDE and that is it can set user passwords. Another benefit of using VBScript it that you can change properties in general, and passwords in particular. CSVDE only adds NEW user and computer objects to Active Directory.
As well as showing you how to master the .SetPassword command, I have alternative examples which make learning points about space as in white space; and also the use of variables.
VBScript Example 1
‘ VBScript to create set a user’s password
‘ Guy Thomas – January 2004
Set objUser = GetObject _
("LDAP://cn=Jeff1,ou=Droitwich,dc=cp,dc=com")
objUser.SetPassword "ip23kpy*o"
Wscript.Echo "Password Changed"
Note 1: The power of this VBScript comes from the GetObject and the .SetPassword verbs.
Note 2: If you try this script, then alter the LDAP path cn=Jeff1,ou=Droitwich,dc=cp,dc=com to reflect your domain and OU.
Note 3: The WScript.Echo statement is not strictly necessary in this password script, but I like confirmation that action took place.
Here are Alternative VBScripts to reset passwords
Spot the difference between Example 1 (above) and Example 2?
VBScript Example 2
‘ VBScript to create set a user’s password
‘ Guy Thomas – January 2004
Set objUser = GetObject _
("LDAP://cn=Jeff1,ou=Droitwich,dc=cp,dc=com")
objUser.SetPassword "ip23kpy*o"
WScript.ECHO "Password Changed"
Note 1: The difference is on line 4. There is space, as in spacebar, at the very beginning of the line and that causes VBScript to halt.
A string variable example of setting a password
By using a string variable to control the actual password, you could have the passwords in one of the columns of an import spreadsheet. The other factor if you were importing would be a Do… Loop until to read through each row of users.
Guy Recommends: SolarWinds’ Free Bulk Import Tool
Import users from a spreadsheet. Just provide a list of the users with their fields in the top row, and save as .csv file. Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.
Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.
If you need more comprehensive software, download a free trial of SAM (Server & Application Monitor)
VBScript Example 3
‘ VBScript to create set a user’s password
‘ Guy Thomas – January 2004
DIM strPWD, strLDAP
strPWD = "x!f98btw"
strLDAP = "Jeff1,ou=Droitwich,dc=cp,dc=com"
Set objUser = GetObject _
("LDAP://cn=" & strLDAP )
objUser.SetPassword strPWD
WScript.ECHO "Password Changed"
Note 1: Here we introduce variables. The point is that a string variable would be useful where you read the data from a file. (As shown in my eBook.)
Note 2: That space as in white space does not matter within the bracket ("LDAP://cn=" & strLDAP )
Note 3: Pay close attention to the position of the speech marks in the "LDAP://cn" statement.
Note 3: This IS one of those scripts that you can run again and again without getting error message ‘Object already exists’.
Note 1 : I have a new script to Set Passwords
Note 2: I have a new script to force users to change password at next logon
Download your eBook: Creating Exchange mailboxes with VBScript- only $6.25
Create mailbox-enabled users. Add mailboxes to existing users in Active Directory. Step-by-step instructions on how to use VBScript to generate users with mailboxes. Combine VBScripts with CSVDE to import users from spreadsheets.
You get a printer friendly version with copy enabled, and no expiry date. It runs to 55 A4 pages.
See Also