PowerShell Ezine, Logon Scripts

Guy's Scripting Ezine 11 - Passwords

Contents of Guy's Scripting Ezine 11 - Passwords

This week's script

This week's theme is changing passwords.  I will show you how to set the password on a new account or change an existing account password.  When you  copy and paste the script below, remember to substitute your domain for: cp.com and also your organizational unit for ou=Worcester.

ˆ

1) Creating your user (Recap)

This is an extra preliminary script to create a user so tht we can change their password.  Copy and paste the examples below into notepad.exe

IMPORTANT: Change the 'ou=Worcester' to an OU in your Active Directory.

N.B. Change 'cn=Guido' to the name of a user you wish to create.

Save the script with a .vbs extension, and double click the file to test it.

'
' VBScript.
' Example script to create a user called Guido in OU Worcester
' Note the domain cp.com should be changed.

Set objOU = GetObject("LDAP://OU=Worcester,dc=cp,dc=com")
Set objUser = objOU.Create("User", "cn=GuidoT")
objUser.Put "sAMAccountName", "GuidoT"
objUser.Put "givenName", "Guido"
objUser.Put "initials", "A.G."
objUser.Put "sn", "Thomas"
objUser.Put "displayName", "Guido Thomas"
objUser.SetInfo
 

 

Learning Points

Set objOU = GetObject   This statement references the correct container or organizational unit in Active Directory.  You will need to change the ("LDAP://OU = Worcester, dc=cp, dc=com") to reflect your domain and your OU.

Set objUser = objOU.Create   This statement tells Active Directory that you wish to add a user object (not a computer object) and that you want to create not delete.

objUser.Put  This is the best way to add the attributes of the user GuidoT.

SetInfo means write the objUser into Active Directory

ˇ

2) Setting a user's password

'
' VBScript.
' To SET a user's password.

 Set objUser = GetObject _
("LDAP://cn=GuidoT,ou=Worcester,dc=cp,dc=com")
objUser.SetPassword "gU1d0*!"

 

Learning Points

The key method here is SetPassword.  Best practice is to use UPPER case, lower case, numbers and even non-alphanumeric characters so that the passwords are very difficult to guess, for example STL01isRams.  If your password policy is less strict then suggest that they use phrases in their passwords, for example  (ST Louis Rams).

3) Changing a user's password

'
' VBScript.
' To CHANGE a user's password. N.B. you must know the original password

 Set objUser = GetObject _
("LDAP://cn=GuidoT,ou=Worcester,dc=cp,dc=com")
objUser.ChangePassword "gU1d0*!", "ant0n10#!"

 

 

Learning Points

The above script will change a password but only if you already know the existing password.  Notice a different method ChangePassword here, compared with SetPassword in 2) Setting the User's password in the middle script.

Summary

In this Ezine you learnt how to set or change a users password.  The technique uses to key methods, objUser.ChangePassword and objUser.SetPassword.  We also had a refresher on the .put and .Setinfo methods of adding or amending user's properties.

See more on setting passwords here

Computer Training Software - Recommended Training VideosGuy Thomas recommends Computer Training Software

Their topics and material are ideal for getting you started with VBScript.  The videos are easy to follow and you can control the pace.  Try their free demo material and then see if you want to buy the full package. See more about VB Script Training CD.


 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

Home Copyright © 1999-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.