Script to enable accounts and set passwords
Filed under: Active Directory
Comments: None
Script to enable accounts and set password
http://www.computerperformance.co.uk/ezine/ezine23.htm
Pre-requisites. You need either a Windows 2000 or Server 2003 domain controller for this script to work.
Change Line 11 “OU=Cowbridge ,” to the name of one of your OUs. Alternatively, create an OU called Cowbridge.
Please make sure that the OU has users and that their accounts are disabled. (Right Click any account, select (‘Disable Account’)
Copy and paste the script below into notepad.
Save the file with .vbs extension e.g. AccountControl.vbs
Double click and observe the message box
Importance of adding : pwdLastSet
512 – Enable Account
514 – Disable account
544 – Account Enabled – Require user to change password at first logon
66048 – Password never expires
262656 – Smart Card Logon Required
(save as *.vbs)
‘ Set AccPwd.vbs
‘ VBScript to require users change passwords at next logon
‘ Author Guy Thomas http://computerperformance.co.uk/
‘ Version 2.2 – March 21st 2004
‘ —————————————————————–‘
Option Explicit
Dim objOU, objUser, objRootDSE
Dim strContainer, strLastUser, strDNSDomain, intCounter, intAccValue
Set objRootDSE = GetObject(“LDAP://RootDSE”)
strDNSDomain = objRootDSE.Get(“DefaultNamingContext”)
strContainer = “OU=Cowbridge ,”
intAccValue = 544
strContainer = strContainer & strDNSDomain
set objOU =GetObject(“LDAP://” & strContainer )
intCounter = 0
For each objUser in objOU
If objUser.class=”user” then
objUser.SetPassword “P@££er2004”
objUser.SetInfo
objUser.Put “userAccountControl”, intAccValue
objUser.SetInfo
intCounter = intCounter +1
strLastUser = objUser.Get (“name”)
End if
next
WScript.Echo intCounter & ” Users change pwd next logon. Value ” _
& intAccValue
WScript.Quit