Password Notification email

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 4 months ago.

  • Author
    Posts
  • #5738

    by southtx07 at 2013-03-29 15:31:29

    Hello, I created a script to notify users in a specific OU that their password will expire in 10 days. How do I schedule this to run every month? The scheduled task does not have the capability for me to run every 20 days. Although I see that I can schedule every x days for every month, my problem would be passwords are created on different days. Surly there has to be another way other than creating the passwords on the first of the month. Do I need to modify my script below? If yes then how so? Any help would be much appreciated. The script runs fine in powergui.

    $smtpServer="smtp.abc.com"
    $users = Get-QADUser -Email "*@xyz*" -SearchRoot "ou=abc, dc=abc, dc=com" -IncludedProperties mail
    foreach ($user in $users)
    {
    $Name = (Get-QADUser $user | foreach { $_.GivenName})
    $emailaddress = $user.mail
    $dayslefttillexpiration = (([datetime]::FromFileTime((Get-QADUser -Identity $user -IncludedProperties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed"))-(Get-Date)).Days

    $subject="Password Notification"
    $body ="
    $Name,

    Your password will expire in $dayslefttillexpiration days. Please change as soon as possible.

    Thanks,

    "

    if ($dayslefttillexpiration -le 10)
    {
    Send-Mailmessage -smtpServer $smtpServer -from 'noreply@email.com' -to $emailaddress -subject $subject -body $body -bodyasHTML -priority High

    }

    }

    by DonJ at 2013-03-29 15:37:52

    As a note, you can use the CODE button in the editor to format your code. Easier to read 😉

    I'd just schedule it to run every single day, and ONLY mail the people whose passwords expire 10 days from THEN. That way, you get an e-mail when YOUR password is 10 days away.

    by nohandle at 2013-03-30 03:19:05

    [quote="southtx07"]The scheduled task does not have the capability for me to run every 20 days. [/quote]
    Yes it does, it is just not that obvious as it should be. You have to create new trigger, choose to run the task once starting at and then in the box where you may choose how often you want it repeating you write "20 days". You click Ok and in the list of triggers window you may expand the description of the trigger and confirm it is set to 20.00:00:00.

    [quote="DonJ"]I'd just schedule it to run every single day, and ONLY mail the people whose passwords expire 10 days from THEN.[/quote]
    Definitely better approach. I would apply it on every user whose password expires in 10 or less days.

You must be logged in to reply to this topic.