Re: Privision User must change password at next logon, if password changed, set password never expire

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




<klam10411@xxxxxxxxx> wrote in message
news:cb17813d-ca20-440f-afa7-587db4cc4466@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi All,

I am looking for help in being able to create a script that will
provision a specific OU of users. New users will be created with the
flag set for "User must change password at next logon". I can have the
script run weekly, to check if users in that OU has changed their
password, if so, than set their Password never expire".

The closest I found was this script
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_thread/thread/ea73f478f4e87e62

Any help will be much appreciated.

To set "user must change password at next logon", assign 0 to the pwdLastSet
attribute. Thereafter any non-zero value means the password has been set at
least once. To assign the setting "password never expires" you set a bit of
the userAccountControl attribute, using the bit mask
ADS_UF_DONT_EXPIRE_PASSWD (with a hex value of &H10000).

If the users in the OU exist, configure to force password changes with code
similar to:
=========
' Bind to OU with Distinguished Name of OU.
Set objOU = GetObject("LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com";)

' Filter on users.
objOU.Filter = Array("user")

' Enumerate all users in the OU.
For Each objUser In objOU
' Expire password, so user must change password at next logon.
objUser.pwdLastSet = 0
' Save change.
objUser.SetInfo
Next
========
A script to run periodically to check if the password has been changed and
then set "password never expires" could be similar to:
========
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000

' Bind to OU with Distinguished Name of OU.
Set objOU = GetObject("LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com";)

' Filter on users.
objOU.Filter = Array("user")

' Enumerate all users in the OU.
For Each objUser In objOU
' Check if password has been set.
If (objUser.pwdLastSet <> 0) Then
' Configure user so password never expires.
lngFlag = objUser.userAccountControl
lngFlag = lngFlag Or ADS_UF_DONT_EXPIRE_PASSWD
objUser.userAccountControl = lngFlag
objUser.SetInfo
End If
Next
=======
If you are creating users, and want to specify an initial password and
configure so the user must change it at first logon, the script to create
one user could be similar to below:
=========
' Bind to OU with Distinguished Name of OU.
Set objOU = GetObject("LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com";)

' Specify "Common Name" of new user (or prompt for this value).
strCN = "Jim Smith"

' Specify the "pre-Windows 2000 logon name" (or prompt for this value).
strNTName = "JSmith"

' Create the new user object.
Set objUser= objOU.Create("user", "cn=" & strCN)
' Assign mandatory attributes.
objUser.sAMAccountName = strNTName
' Save new object in AD.
objUser.SetInfo

' Assign initial password
objUser.SetPassword = "xZy$321#"

' Enable the user account.
objUser.AccountDisabled = False

' Expire the password.
objUser.pwdLastSet = 0

' Save changes.
objUser.SetInfo
=========
Or you might want to use an example VBScript program that creates users from
the information in an Excel spreadsheet linked here:

http://www.rlmueller.net/CreateUsers.htm

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


.



Relevant Pages

  • Re: Script just stops running even though on error resume next
    ... The WinNT provider is available if the client is Windows 2000 or above. ... If you run the script ... after logon the error message should indicate the line number and hopefully ... the "After bind:" entry. ...
    (microsoft.public.scripting.vbscript)
  • Re: Force password reset for administrator
    ... My script is in fact doing the same as yours. ... Is also required to set the password reset bit. ... logf.WriteLine(" Set administrator account to password changed after next ... expired, your code would configure so passwords no longer expire. ...
    (microsoft.public.scripting.vbscript)
  • Re: AD Script to set passwords to expire in 10 days
    ... I'm saying to run the script that sets the pwdLastSet attribute in scheduled maner. ... "Joe Kaplan" wrote in message ... Co-author of "The .NET Developer's Guide to Directory Services ... If you set the value to -1 and changed your domain pwd policy so that passwords expire in 10 days, then everyone's password would expire in 10 days, so that might get you what you want. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Help With Password Last Changed
    ... password to expire in 1 day and everyone but my test user was set to ... to have the passwords expire after 90 days. ... dtmValue = objUserLDAP.PasswordLastChanged ... This is the script I was using. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Dynamically Moving Computer Objects
    ... Is there a way that I can move them at login, where the script would ... Bind to the computer object. ... In a logon script, the ADSystemInfo ...
    (microsoft.public.windows.server.scripting)