Link to home
Start Free TrialLog in
Avatar of AC_UK
AC_UK

asked on

Setting AD user attributes programatically

Hello,

I am trying to write a few scripts that will in basic terms adds the  "User must change password on next logon" flag and removes the "Password never expries flag"

Done a fair bit of searching but nothing as yet.

These scripts are to be run on XP SP1 / SP2. Pref VBS, Dos or WSI
ASKER CERTIFIED SOLUTION
Avatar of CSecurity
CSecurity
Flag of Iran, Islamic Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is exactly what you want.... But previous is good too... But this example is exactly the code that you was looking for



Option Explicit
Dim objOU, objUser, objRootDSE, objShell
Dim strContainer, strDNSDomain, strPassword
Dim intPwdValue

' Bind to Active Directory Domain
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

' -------------------------------------------------------------'
' Important change OU= to reflect your domain
' -------------------------------------------------------------'
strContainer = "OU=Accounts, "
strPassword = "P@ssw0rd"
strContainer = strContainer & strDNSDomain

' Here we force a change of password at next logon
intPwdValue = 0

' Loop through OU=, setting passwords for all users
set objOU =GetObject("LDAP://" & strContainer )
For each objUser in objOU
If objUser.class="user" then
objUser.SetPassword strPassword
objUser.Put "PwdLastSet", intPwdValue
objUser.SetInfo
End If
Next
' Optional section to launch Active Directory Uses and Computers
Set objShell=CreateObject("WScript.Shell")
objShell.Run "%systemroot%\system32\dsa.msc"

WScript.Quit

' End of Sample PwdLastSet Advanced VBScript
Avatar of AC_UK
AC_UK

ASKER

The first example does what I want almost.......

It does need to remove the flag for " Password never expires" at the same time

Also I need the option to import a list of names rather than just target a sinlge OU.


If you can manage that you have the points.
You mean you want to set here "OU=Accounts" with a list of OUs instead of Accounts?
Avatar of AC_UK

ASKER

All done with that anyway. Thanks for the Script.
You are welcome.