一般来说,在部署了微软活动目录的企业域环境中,为了安全起见,不会将用户的密码设置为永不过期,通常设置为60天到90天更改一次,相对比较安全。在密码快要过期的时候,用户登录 Windows 时会有提醒修改密码。不过,也会有很多员工根本不去看这个提示甚至忽略掉,一旦员工域帐号的密码过期时间是在公众假期甚至是外地出差期间,那么结果就是包含邮件在内的相关应用系统无法登陆。随之给域管理员的工作带来压力。有各种各样的方法可以减少此种事件发生,一些第三方工具甚至可以开放给员工自助的密码忘记/重设服务,我们这里不做探讨。
'############################ PasswordCheck.vbs ################################ ' Author: Randy Zhong ' Source: https://github.com/randyzhong/ ' Description: This script use VBScript to check user's password expiration date. ' If Lastdate equals 7,5,3,2,1, DisplayName,Email,LastDate,Runtime ' will be recorded to OutFile in CSV format. ' Version: 1.0.0 '#################################################################################
' IMPORTANT VARIABLES TO EDIT LDAPDomain = "LDAP://OU=FABRIKAM Users,DC=Fabrikam,DC=com" BiosDomain = "FABRIKAM" OutFile = "C:\PwdCheck\passexpired.csv" ' END OF IMPOTANT VARIABLES TO EDIT
' BEGIN OF CODE - DON'T EDIT Set objDomainNT = GetObject("WinNT://" & BiosDomain) intMaxPwdAge = objDomainNT.Get("MaxPasswordAge") If intMaxPwdAge < 0Then WScript.Echo("Password never expired!") WScript.Quit Else intMaxPwdAge = (intMaxPwdAge/SEC_IN_DAY) EndIf
Set fso = CreateObject("Scripting.FileSystemObject") Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command")
######################## Sendmail-PassExpired.ps1 ############################# # Author: Randy Zhong # Source: https://github.com/randyzhong/ # Description: This script uses Send-MailMessage cmdlet to send HTML format # message with high priority. # Version: 1.0.0 #################################################################################