Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell Script that will notify the user when their password was changed

$
0
0

Hello,    I have the desire to have a script that runs frequently (each hour) that will send an email to the A/D user when the password was changed.

I have found the script below, but it does not work.    Curious if any script masters could look at this and see what is wrong.

$minuteschanged=60
$timeminus1=(get-date).addminutes("-$minuteschanged")

$users=get-aduser -searchbase "dc=xxx,dc=xxx,dc=com" -filter * -properties name,mail,samaccountname,passwordlastset | Where

{$_.PasswordLastSet -ge $timeminus1} | ForEach-Object

{
#Send Email to users

$SMTPServer = "mailxx.xxx.xxx.com"

$from = "password@xxxgmt.com"

$to = $_.mail

$SamAccountName = $_.name

$LastSet = $_.PasswordLastSet

$subject = "Your password has been reset"

$emailbody = "Hello $SamAccountName your password was reset on $LastSet"

$mailer = new-object Net.Mail.SMTPclient($SMTPserver)

$msg = new-object Net.Mail.MailMessage($from, $to, $subject, $emailbody)

$mailer.send($msg)
}


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>