Password Expiry Email Notification

This script will email a user in the event that their password is due to expire in X number of days.

 
 
 
 
 
4.6 Star
(131)
53,784 times
Add to favorites
Active Directory
10/10/2017
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Credentials
    1 Posts | Last post 12:27 PM
    • How do I set credentials?
      
      Will also need to activate TLS/SSL for using O365 smtp relay.
      
      Thank you
  • Getting client not authenticated error
    2 Posts | Last post Fri 6:35 AM
    • Hi,
      
      First off ... great script! I am running into an issue though. The script properly checks the domain for almost expired passwords but it doesn't send the mail to the users or the test recipient. I am running this script directly on my SMTP server. 
      
      I get this error :
      
      The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated"
    • So you will need to provide credentials to relay it sounds like.
      
      
  • RE: No E-mail Being Sent
    7 Posts | Last post Fri 6:34 AM
    • I have setup a scheduled task, which did not function, and had no errors. I have then run the script manually with the specified variables and am not receiving any e-mails. I did update the script for proper capitalization (just to be sure - likely completely irrelevant) to no avail. It shows no errors, and seems to parse all variables and Active Directory properly. The Send-MailMessage command works just fine on it's own.
    • First thing to do is run it from within a PowerShell window, not a scheduled task and make sure it works there.
      
      
    • I have done so. It runs through with no errors, but, does not send the e-mails.
    • I removed the "interval" variable from the command and it seems to be functioning now.
    • Ok i would add in the -status variable and the -interval variable and see what it shows.
      
      If you are using 2008R2 or similar you may need to check you have the most recent version.
    • I am running 2012 R2. I have been able to get the scheduled task to run properly by leaving off the -interval option, and e-mails are being delivered properly at this time. I also modified the script to provide a much more visually-appealing company branded e-mail template.
    • That's great, it's why i shared it.
  • -Interval Breaks E-Mail in Scheduled Task
    2 Posts | Last post Fri 6:33 AM
    • When running the script manually with the -interval switch, everything works fine. When I run the script as a scheduled task with the -interval switch, e-mails don't send. I added -status to the command line and it says it's sending e-mail but it never does. As soon as I remove -interval, e-mails send fine. 
    • Weird!
      
      Can you get in touch at http://titlerequired.com/support
      
      I spent a little bit of time testing this morning, Windows 10 + 2008R2 DC and it seemed to work as expected.
  • Interval Breaks E-Mail in Scheduled Task
    2 Posts | Last post Fri 6:33 AM
    • Hi
      
      Same problem here. if i use the interval switch in a scheduled Task no mails are sent.
      If i run it without interval or from within a PowerShell windows everythin works fine.
      
      Tested on Windows 2012 R2
    • Weird!
      
      Can you get in touch at http://titlerequired.com/support
      
      I spent a little bit of time testing this morning, Windows 10 + 2008R2 DC and it seemed to work as expected.
  • Group Managed Service Account returns weird results
    3 Posts | Last post October 16, 2017
    • When the script is used in a Scheduled Task setup to use a gMSA, it doesn't return the correct set of users.  The same task when switched to a normal user account works great.  Looks like the Get-ADUsers command filtering isn't working correctly when using a gMSA.  Any ideas?
      
      Thanks!
    • Nevermind.  I figured it out after reading through all 20 pages of questions.  Needed to delegate a group to have Read access at the top level of the domain and then drop the gMSA in the group.
    • You may not need this now, but check this out.
      https://www.youtube.com/watch?v=eLo5sylezA0
  • Using latest script v2.6 Oct 17
    2 Posts | Last post October 13, 2017
    • I would love to use your script and looks to be just want I need, how would I add all my details to it? and also make use of the email log to me as administrator? I am a PS newbie!
      
      All you help would be most appreciated.
      
      Thanks
    • ......So, I have followed the YouTube video about scheduled task, and added; -command "C:\JM_Scripts\PasswordChangeNotification.ps1 -smtpServer oursmtpserver -expireInDays 14 -from us@us.com -Logging -LogPath C:\JM_Scripts\logFiles", it generates the logfile, but its empty? and I don't see any emails sent? I can use the send function alone in PS and it works?
      
      Please HELP... Thanks
  • How to modify this script to run over an specific OU
    3 Posts | Last post October 11, 2017
    • I would like to run this script not over all the AD domain users, just only over an OU of users that I have created in the AD.
      
      Can you help me to do this modification on the script for only an OU to run.
      
      Thanks in advance.
    • Adjust line 100 (version 2.6) to include the -searchbase parameter. 
      
      https://technet.microsoft.com/en-gb/library/ee617241.aspx
    • Sorry, I am a beginner on this. So, can you do it for me please ? including the right parameter in the right line. The OU path to apply the script is: 
      OU=peru,OU=GNBsudameris,DC=GNB,DC=loc
      
      I'd appreciate it.
      Thanks.
  • Error sending mail to the user
    5 Posts | Last post October 10, 2017
    • Method invocation failed because [System.Object[]] doesn't contain a method named 'Contains'
      Running windows Server 2008 R2 SP1
    • What version of PowerShell do you have?
    • Just tried this on 2008 R2 with SP1, PowerShell v2.0 no errors.
    • No, my mistake, it does. Will investigate.
    • You will need to change line 205 to this:
      if(($interval) -Contains ($daysToExpire))
  • What about multiple expiration windows?
    8 Posts | Last post October 06, 2017
    • Could this script be modified to send notifications 7 days, 3days and 1 day prior to expiration?  What would that look like?
    • Yes this is possible to do, lots of questions and answers below on that.
      
      
    • Also, I am getting the following errors in the script:
      You cannot call a method on a null-valued expression.
      At C:\pwnotify\PasswordChangeNotification.ps1:190 char:41
      +     $samLabel = $samAccountName.PadRight <<<< ($padVal," ")
          + CategoryInfo          : InvalidOperation: (PadRight:String) [], RuntimeE
         xception
          + FullyQualifiedErrorId : InvokeMethodOnNull
      
      Add-Member : Cannot bind argument to parameter 'InputObject' because it is null
      .
      At C:\pwnotify\PasswordChangeNotification.ps1:207 char:27
      +         $user | Add-Member <<<<  -MemberType NoteProperty -Name SendMail -Val
      ue $errorMessage
          + CategoryInfo          : InvalidData: (:) [Add-Member], ParameterBindingV
         alidationException
          + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
         icrosoft.PowerShell.Commands.AddMemberCommand
      
      Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null
      .
      At C:\pwnotify\PasswordChangeNotification.ps1:226 char:32
      +     $notifiedUsers | Export-CSV <<<<  $logFile
          + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingV
         alidationException
          + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
         icrosoft.PowerShell.Commands.ExportCsvCommand
      
      Any thoughts?
    • Nevermind...  I'm a dope.
    • i Just updated to version 2.6 including a new parameter to do this, interested to hear what you think.
      https://www.youtube.com/watch?v=zbySaQ2qWA4
    • Bro...  That's BRILIANT!  Thank you so much.
    • Alright...  One more question.  I'm getting this error:
      
      Method invocation failed because [System.Object[]] doesn't contain a method named 'Contains'.
      
      Any Ideas?
    • Which OS are you using?
1 - 10 of 315 Items