Dbyte
Technical User
- Mar 6, 2002
- 87
Goal: a text file showing the password status for every user in AD.
Problem: the script quits unexpectedly as soon as it gets to a user whose "User must change password at next logon" box is checked. My understanding is that this status should trigger the "password has expired" Else routine. No department, display name, or status appears in the text file.
Here is my code:
Code above derived from with further assistance from
If I run the script from the MSDN page against the user who causes my script to fail I get a "Maximum password age is 360 days" response (<- removed from my script) followed by "The password has expired".
The part of the script where I think the error resides is in red. Thanks in advance for any assistance.
Problem: the script quits unexpectedly as soon as it gets to a user whose "User must change password at next logon" box is checked. My understanding is that this status should trigger the "password has expired" Else routine. No department, display name, or status appears in the text file.
Here is my code:
Code:
On Error Resume Next
Dim oFSO, oGroup, oUser, oDomain, oMaxPwdAge, oFile
Dim iUserAccountControl, dtmValue, iTimeInterval, dblMaxPwdNano
Set oFSO = CreateObject("scripting.filesystemobject")
Set oGroup = GetObject("LDAP://ou=Departments,dc=domain,dc=somesite,dc=org")
Const ForWriting = 2
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Const ONE_HUNDRED_NANOSECOND = .000000100
Const SECONDS_IN_DAY = 86400
Sub enumMembers(oGroup)
For Each oUser In oGroup
If oUser.Class = "user" Then
iUserAccountControl = oUser.Get("userAccountControl")
If iUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then
oFile.WriteLine oUser.department & "/" & oUser.displayName & vbTab & "password does not expire"
Else
dtmValue = oUser.PasswordLastChanged
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
oFile.WriteLine oUser.department & "/" & oUser.displayName & vbTab & "password has never been set"
Else
iTimeInterval = Int(Now - dtmValue)
oFile.WriteLine oUser.department & "/" & oUser.displayName & vbTab & iTimeInterval & " days old"
End If
Set oDomain = GetObject("LDAP://dc=domain,dc=somesite,dc=org")
Set oMaxPwdAge = oDomain.Get("maxPwdAge")
If oMaxPwdAge.LowPart = 0 Then
oFile.WriteLine oUser.department & "/" & oUser.displayName & vbTab & "password does not expire"
[COLOR=red]Else
dblMaxPwdNano = _
Abs(oMaxPwdAge.HighPart * 2^32 + oMaxPwdAge.LowPart)
dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND
dblMaxPwdDays = Int(dblMaxPwdSecs / SECONDS_IN_DAY)
If iTimeInterval >= dblMaxPwdDays Then
oFile.WriteLine oUser.department & "/" & oUser.displayName & vbTab & "password has expired."
End If
End If[/color]
End If
ElseIf oUser.Class = "organizationalUnit" or oUser.Class = "container" Then
enumMembers(oUser)
End If
Next
End Sub
Set oFile = oFSO.CreateTextFile("PasswordStatus.txt", ForWriting, True)
Call enummembers(ogroup)
Code above derived from with further assistance from
If I run the script from the MSDN page against the user who causes my script to fail I get a "Maximum password age is 360 days" response (<- removed from my script) followed by "The password has expired".
The part of the script where I think the error resides is in red. Thanks in advance for any assistance.