Enable Password Never Expires in Active Directory

September 10, 2010

Here’s a very simple script I wrote in VBScript to reset this flag if it doesn’t exist for all users in any given OU.

[vb]Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Set objContainer = GetObject("LDAP://cn=Users,dc=domain,dc=local")
objContainer.Filter = Array("user")
For Each objUser In objContainer
lngFlag = objUser.Get("userAccountControl")
If (lngFlag And ADS_UF_DONT_EXPIRE_PASSWD)=0 Then
lngFlag = lngFlag Xor ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userAccountControl", lngFlag
objUser.SetInfo
wScript.echo objUser.Name
End If
Next[/vb]

+1 this post if it helped you!

Leave a Reply