Active Directory Password Expiry Notification

Richard Fleming

Driven to computers at a young age, I wear my geek badge with pride! I have an active interest in all things 'tech', but absolutely love web development. Building something that gives you instant gratification and is visible to all attached to the net is a rush!

You may also like...

4 responses

  1. apperrault says:

    Richard, I love this script. This is almost 100% what I am looking for. My company wants to only send out emails when people’s passwords are at 7, 3, and 1 day. How would I introduce something like this into this script. We want to run the script as a scheduled task on a daily basis, but my users will freak if we send them emails every day.

    Thanks

    • I’m glad it helps!

      Looking at the code, you’d have to make a few changes. I’d suggest changing line 24 to read $pwdNotificationStartInDays = 7, then adding a new array right below, say $pwdExpiryNotificationDays = Array(1, 3, 7).

      Then you go down to the IF block on line 262 and change it to something like this:

      # Prepare-SMTPMessage if password expires less than or on a certain day
      if ( $objPwdTimeLeft.Days -le $ghtSettings.Pwd.NotificationStartInDays ) {
      # Only send notices on specific days
      if ( $pwdExpiryNotificationDays -contains $objPwdTimeLeft.Days ) {
      Send-PwdExpiryEmailToUsers $strSendTo $objUser.DisplayName $objPwdTimeLeft $now
      }
      Populate-Report -strDisplayName $objUser.DisplayName -objPwdTimeLeft $objPwdTimeLeft -now $now
      }

      You’ll have to try that out before you put into production… but that should do the trick.

      Cheers,

      Rich

  2. Brian says:

    How can I change the email to read Attention Firstname Lastname,? Instead of the display name… ?

    • First thing, in the function Get-PasswordExpiredUsers, change $objUsers to equal the following:
      $objUsers = Get-ADUser -Filter $strFilter -Properties SamAccountName, DisplayName, mail, PasswordLastSet, givenName, sn

      Then inside the ForEach loop (near the top), you need to make a new variable equal to $objUser.giveName and $objUser.sn:
      $userFName = $objUser.givenName + " " + $objUser.sn

      Finally you need to then change the call near the bottom of the ForEach loop to Populate-Report, and change $objUser.DisplayName to your new variable:
      Populate-Report -strDisplayName $userFName -objPwdTimeLeft $objPwdTimeLeft -now $now

      That should do the trick.

Leave a Reply

%d bloggers like this: