DIM objSysInfo, objUser, objDomain, objWShell
DIM strUserDN, strDomainDN, strUserCN
DIM maxPwdAge, numDays, daysToExpiration, objPwdExpires
set objWShell = WScript.CreateObject( "WScript.Shell" )
SET objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
strDomainDN = objSysInfo.DomainShortName
SET objDomain = GetObject("LDAP://" & strDomainDN)
SET objUser = GetObject("LDAP://" & strUserDN)
SET objUserName = GetObject("WinNT://" & strDomainDN & "/" & strUserCN,User)
objPwdExpires = objUserName.Get("UserFlags")
If (objPwdExpires And &H10000) <> 0 Then
Msgbox "User password does not expire"
' Check the domain policy for password changes:
SET maxPwdAge = objDomain.Get("maxPwdAge")
' Calculate the number of days that are held in this value, add the days to last password set date
' and so know how many days until it needs changing
numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + maxPwdAge.LowPart) / CCur(-864000000000)
whenPasswordExpires = DateAdd("d", numDays, objUser.PasswordLastChanged)
daysToExpiration = DateDiff("d", Now(),whenPasswordExpires)
MsgBox "Password expires on " & whenPasswordExpires & " ( " & daysToExpiration & " days )"
IF daystoExpiration <=1 THEN
msgbox "PLEASE CHANGE YOUR PASSWORD." & CR & CR & "Unless you change your password today you may lock your account out
as it expires at " & whenPasswordExpires & CR & CR & "Plase press Control-Alt-Delete and choose Change Password now.",
16+0,"PASSWORD EXPIRES on " & whenPasswordExpires
IF daystoExpiration <=5 THEN msgbox "Please note you have " & daystoexpiration & " days left to change your password.
Please change before then to avoid locking your account." ,48+0,"PASSWORD EXPIRES on " & whenPasswordExpires
Open in new window
If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $159.20.
Premium members get this course for $37.50.
Premium members get this course for $31.25.
Premium members get this course for $174.99.
Premium members get this course for $349.00.
Premium members get this course for $62.50.
Premium members get this course for $389.00.