I found the following code and made a couple of minor changes. The code looks up Active Directory for the users password age and produces a pop-up if the password will expire in 14 days or less. What I would like to do is alter the code so that I could add variables, like vacation periods, so if their password will expire over break the pop-up will be displayed before the break period.
The users password will expire in 45 days. Summer break is coming up, which lasts 70 days. The 14 days setting will not help in this instance. I have 4 vacation periods that I would like to add to the script.
Not sure what the best way to do this. Maybe a Select Case code using current date then 4 selected dates. Any other time the 14 day setting should apply.
' First, get the domain policy.
warningDays = 14
Set LoginInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & LoginInfo.UserName & "")
strDomainDN = UCase(LoginInfo.DomainDNSName)
strUserDN = LoginInfo.UserName
Set oDomain = GetObject("LDAP://" & strDomainDN)
Set maxPwdAge = oDomain.Get("maxPwdAge")
' Calculate the number of days that are
' held in this value.
numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + _
maxPwdAge.LowPart) / CCur(-864000000000)
'WScript.Echo "Maximum Password Age: " & numDays
' Determine the last time that the user
' changed his or her password.
Set oUser = GetObject("LDAP://" & strUserDN)
' Add the number of days to the last time
' the password was set.
whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged)
fromDate = Date
daysLeft = DateDiff("d",fromDate,whenPasswordExpires)
'WScript.Echo "Password Last Changed: " & oUser.PasswordLastChanged
if (daysLeft < warningDays) and (daysLeft > -1) then
MsgBox "Password Expires in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & chr(13) & chr(13) & "Please change your password. Press CTRL-ALT-DEL and" & chr(13) & "select 'Change a password' option.", VBSystemModal, "PASSWORD EXPIRATION WARNING!"
' Clean up.
Set oUser = Nothing
Set maxPwdAge = Nothing
Set oDomain = Nothing