All Forums >> [Scripting] >> WSH & Client Side VBScript >> Re: Password Expiring Email Notification Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
OK guys here is the script that I am trying now. My domain name is testing. I have created a userid called testid. I keep getting the following error. Thanks.
Line:4 Char:1 Error: A referral was returned from the server Code: 8007202B
Set objUserLDAP = GetObject _ ("LDAP://CN=testid,OU=Users,DC=testing,DC=com") intCurrentValue = objUserLDAP.Get("userAccountControl")
If intCurrentValue and ADS_UF_DONT_EXPIRE_PASSWD Then Wscript.Echo "The password does not expire." Else dtmValue = objUserLDAP.PasswordLastChanged Wscript.Echo "The password was last changed on " & _ DateValue(dtmValue) & " at " & TimeValue(dtmValue) & VbCrLf & _ "The difference between when the password was last set" & _ "and today is " & int(now - dtmValue) & " days" intTimeInterval = int(now - dtmValue)
Set objDomainNT = GetObject("WinNT://testing") intMaxPwdAge = objDomainNT.Get("MaxPasswordAge") If intMaxPwdAge < 0 Then WScript.Echo "The Maximum Password Age is set to 0 in the " & _ "domain. Therefore, the password does not expire." Else intMaxPwdAge = (intMaxPwdAge/SEC_IN_DAY) Wscript.Echo "The maximum password age is " & intMaxPwdAge & " days" If intTimeInterval >= intMaxPwdAge Then Wscript.Echo "The password has expired." Else Wscript.Echo "The password will expire on " & _ DateValue(dtmValue + intMaxPwdAge) & " (" & _ int((dtmValue + intMaxPwdAge) - now) & " days from today" & _ ")." End If End If End If
This is what works for me. I'm not very good with scripts so I'm sure it can be cleaned up. I just pieced different scripts together. The only thing that I would like to add to this script is the user id for the person(somewhere in the email). I have not been able to figure that out yet. Remember to set your domain & password informaton. Hope this helps.
HTML = "<!DOCTYPE HTML PUBLIC""-//IETF//DTD HTML//EN"">" HTML = HTML & "<HTML><HEAD><TITLE>MG Account Delete Alert</TITLE></HEAD>" HTML = HTML & "<BODY style='BORDER-RIGHT: white 1px solid; PADDING-RIGHT: 10px; BORDER-TOP: #002f91 8px solid;" HTML = HTML & "PADDING-LEFT: 10px; SCROLLBAR-FACE-COLOR: #cce6ff; FONT-SIZE: 10pt; PADDING-BOTTOM: 10px;" HTML = HTML & "MARGIN: 10px 10px 10px 10px; SCROLLBAR-HIGHLIGHT-COLOR: #002f91; BORDER-LEFT: #002f91 8px solid;" HTML = HTML & "SCROLLBAR-SHADOW-COLOR: #002f91; SCROLLBAR-3DLIGHT-COLOR: #002f91; SCROLLBAR-ARROW-COLOR: #002f91;" HTML = HTML & "PADDING-TOP: 10px; SCROLLBAR-TRACK-COLOR: #002f91; BORDER-BOTTOM: #002f91 8px solid;" HTML = HTML & "FONT-FAMILY: Tahoma; SCROLLBAR-DARKSHADOW-COLOR: #002f91; FONT-FAMILY: arial; BACKGROUND-COLOR: #cce6ff'>" HTML = HTML & "<TABLE width='100%' border=0 valign='top'>" HTML = HTML & " <TBODY>" HTML = HTML & " <TR>" HTML = HTML & " <TD width='100%'>" HTML = HTML & " <DIV align=center>" HTML = HTML & " <CENTER>" HTML = HTML & " <TABLE cellSpacing=0 cellPadding=0 width='100%' border=0>" HTML = HTML & " <TBODY>" HTML = HTML & " <TR>" HTML = HTML & " <TD dheight=25>" HTML = HTML & " <h3 align=center>Changing Network Password</h3>" HTML = HTML & " </TD>" HTML = HTML & " </TR>" HTML = HTML & " </TBODY>" HTML = HTML & " </TABLE>" HTML = HTML & " </CENTER>" HTML = HTML & " </DIV>" HTML = HTML & " </TD>" HTML = HTML & " </TR>" HTML = HTML & " <TR>" HTML = HTML & " <TD>" HTML = HTML & " <TABLE width='100%' cellpadding='20'>" HTML = HTML & " <TBODY>" HTML = HTML & " <TR bgColor=#ffffff>" HTML = HTML & " <TD width='100%' aheight=15>" HTML = HTML & " <font face='Arial' size='2'>" HTML = HTML & " This email is to remind you to change your network password." HTML = HTML & " Passsword Requirments" HTML = HTML & "<br>" HTML = HTML & "<br>" HTML = HTML & " Follow the steps below to change your password." HTML = HTML & "<br>" HTML = HTML & "<br>" HTML = HTML & " 1. Press Ctrl+Alt+Del and select change password" HTML = HTML & "<br>" HTML = HTML & " 2. Verify username" HTML = HTML & "<br>" HTML = HTML & " 3. Log on to:" HTML = HTML & "<br>" HTML = HTML & " 4. Type you current password" HTML = HTML & "<br>" HTML = HTML & " 5. Type your new password twice" HTML = HTML & "<br>" HTML = HTML & " </font>" HTML = HTML & " </TD>" HTML = HTML & " </TR>" HTML = HTML & " </TBODY>" HTML = HTML & " </TABLE>" HTML = HTML & " </TD>" HTML = HTML & " </TR>" HTML = HTML & " </TBODY>" HTML = HTML & "</TABLE>" HTML = HTML & "</BODY>" HTML = HTML & "</HTML>"
set objConn = CreateObject("ADODB.Connection") objConn.Provider = "ADsDSOObject" objConn.Open "Active Directory Provider" set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope) objRS.MoveFirst while Not objRS.EOF Count = Count + 1 strName = objRS.Fields(0).Value & " " & objRS.Fields(1) strLogin = objRS.Fields(2) strEmail = objRS.Fields(3).Value objLargeInt = objRS.Fields(4) UserFlags = objRS.Fields(5) If IsNull(strEmail) Then strEmail = "" intPwdLastSet = objLargeInt.HighPart * 2^32 + objLargeInt.LowPart intPwdLastSet = intPwdLastSet/60/10000000/1440 PwdLastSet = intPwdLastSet + #1/1/1601# PasswordNeverExpires = False If (UserFlags and &H10000) <> 0 then PasswordNeverExpires = True End If PasswordCannotChange = False If (UserFlags and &H00040) <> 0 then PasswordCannotChange = True End If AccountDisabled = False If (UserFlags and &H00002) <> 0 then AccountDisabled = True End If PwdExpired = False If (UserFlags and &H800000) <> 0 then PwdExpired = True End If Today = DateValue(Date) SendReminder = False dtmValue = PwdLastSet intTimeInterval = int(now - dtmValue) intMaxPwdAge = 180 ' NUMBER OF DAYS A PASSWORD IS GOOD FOR daystoexpire = int((dtmValue + intMaxPwdAge) - now) If (daystoexpire < 179) AND (daystoexpire > 0) Then SendReminder = True End If
If (Not PasswordNeverExpires) And (Not PasswordCannotChange) And (Not AccountDisabled) And SendReminder Then Set objMail = CreateObject("CDONTS.NewMail") objMail.From = "email address" objMail.To = strEmail objMail.Subject = "Your Network Password will expire in " & daystoexpire & " days " objMail.Body = HTML objMail.BodyFormat = 0 objMail.MailFormat = 0 objMail.Send Set objMail = Nothing End If